113 lines · cpp
1// RUN: %clang_cc1 -std=c++98 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors2// RUN: %clang_cc1 -std=c++11 %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors3// RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors4// RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors5// RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors6// RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors7// RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx14 -fexceptions -fcxx-exceptions -pedantic-errors8 9namespace std {10 __extension__ typedef __SIZE_TYPE__ size_t;11 12 template<typename T> struct initializer_list {13 const T *p; size_t n;14 initializer_list(const T *p, size_t n);15 };16} // namespace std17 18namespace cwg1004 { // cwg1004: 519 template<typename> struct A {};20 template<typename> struct B1 {};21 template<template<typename> class> struct B2 {};22 template<typename X> void f(); // #cwg1004-f-123 template<template<typename> class X> void f(); // #cwg1004-f-224 template<template<typename> class X> void g(); // #cwg1004-g-125 template<typename X> void g(); // #cwg1004-g-226 struct C : A<int> {27 B1<A> b1a;28 B2<A> b2a;29 void h() {30 f<A>();31 // expected-error@-1 {{call to 'f' is ambiguous}}32 // expected-note@#cwg1004-f-1 {{candidate function [with X = cwg1004::A<int>]}}33 // expected-note@#cwg1004-f-2 {{candidate function [with X = cwg1004::A]}}34 g<A>();35 // expected-error@-1 {{call to 'g' is ambiguous}}36 // expected-note@#cwg1004-g-1 {{candidate function [with X = cwg1004::A]}}37 // expected-note@#cwg1004-g-2 {{candidate function [with X = cwg1004::A<int>]}}38 }39 };40 41 // This example (from the standard) is actually ill-formed, because42 // name lookup of "T::template A" names the constructor.43 template<class T, template<class> class U = T::template A> struct Third { };44 // expected-error@-1 {{is a constructor name}}45 // expected-note@#cwg1004-t {{in instantiation of default argument}}46 Third<A<int> > t; // #cwg1004-t47} // namespace cwg100448 49namespace cwg1042 { // cwg1042: 3.550#if __cplusplus >= 201402L51 // C++14 added an attribute that we can test the semantics of.52 using foo [[deprecated]] = int; // #cwg1042-using53 foo f = 12;54 // since-cxx14-warning@-1 {{'foo' is deprecated}}55 // since-cxx14-note@#cwg1042-using {{'foo' has been explicitly marked deprecated here}}56#elif __cplusplus >= 201103L57 // C++11 did not have any attributes that could be applied to an alias58 // declaration, so the best we can test is that we accept an empty attribute59 // list in this mode.60 using foo [[]] = int;61#endif62} // namespace cwg104263 64namespace cwg1048 { // cwg1048: 3.665 struct A {};66 const A f();67 A g();68 typedef const A CA;69#if __cplusplus >= 201103L70 // ok: we deduce non-const A in each case.71 A &&a = [] (int n) {72 while (1) switch (n) {73 case 0: return f();74 case 1: return g();75 case 2: return A();76 case 3: return CA();77 }78 } (0);79#endif80} // namespace cwg104881 82namespace cwg1054 { // cwg1054: no83 // FIXME: Test is incomplete.84 struct A {} volatile a;85 void f() {86 // FIXME: This is wrong: an lvalue-to-rvalue conversion is applied here,87 // which copy-initializes a temporary from 'a'. Therefore this is88 // ill-formed because A does not have a volatile copy constructor.89 // (We might want to track this aspect under cwg1383 instead?)90 a;91 // expected-warning@-1 {{expression result unused; assign into a variable to force a volatile load}}92 }93} // namespace cwg105494 95namespace cwg1070 { // cwg1070: 3.596#if __cplusplus >= 201103L97 struct A {98 A(std::initializer_list<int>);99 };100 struct B {101 int i;102 A a;103 };104 B b = {1};105 struct C {106 std::initializer_list<int> a;107 B b;108 std::initializer_list<double> c;109 };110 C c = {};111#endif112} // namespace cwg1070113