174 lines · cpp
1// RUN: %clang_cc1 -std=c++98 -pedantic-errors -verify=expected,cxx98 %s2// RUN: %clang_cc1 -std=c++11 -pedantic-errors -verify=expected,since-cxx11 %s3// RUN: %clang_cc1 -std=c++14 -pedantic-errors -verify=expected,since-cxx11 %s4// RUN: %clang_cc1 -std=c++17 -pedantic-errors -verify=expected,since-cxx11 %s5// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify=expected,since-cxx11,since-cxx20 %s6// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify=expected,since-cxx11,since-cxx20,since-cxx23 %s7// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify=expected,since-cxx11,since-cxx20,since-cxx23,since-cxx26 %s8 9// cxx98-no-diagnostics10 11namespace cwg2913 { // cwg2913: 2012 13#if __cplusplus >= 202002L14 15template<typename T>16struct R {17 R(T);18 R(T, T);19};20 21template<typename T>22R(T) -> R<T> requires true;23 24template<typename T>25R(T, T) requires true -> R<T>;26// since-cxx20-error@-1 {{expected function body after function declarator}}27 28#endif29 30} // namespace cwg291331 32namespace cwg2915 { // cwg2915: 2033#if __cplusplus >= 202302L34struct A {35 void f(this void);36 // since-cxx23-error@-1 {{explicit object parameter cannot have 'void' type}}37};38#endif39} // namespace cwg291540 41namespace cwg2917 { // cwg2917: 20 review 2024-07-3042#if __cplusplus >= 201103L43template <typename>44class Foo;45 46template<class ...>47struct C {48 struct Nested { };49};50 51struct S {52 template <typename>53 friend class Foo, int;54 // since-cxx11-error@-1 {{a friend declaration that befriends a template must contain exactly one type-specifier}}55 56 template <typename ...Ts>57 friend class C<Ts>::Nested...;58 // since-cxx11-error@-1 {{friend declaration expands pack 'Ts' that is declared it its own template parameter list}}59};60#endif61} // namespace cwg291762 63namespace cwg2918 { // cwg2918: 2164 65#if __cplusplus >= 202002L66 67namespace Example1 {68 69template<bool B> struct X {70 void f(short) requires B;71 void f(long);72 template<typename> void g(short) requires B;73 template<typename> void g(long);74};75 76void test() {77 &X<true>::f; // since-cxx20-error {{reference to overloaded function could not be resolved}}78 &X<true>::g<int>; // since-cxx20-error {{reference to overloaded function could not be resolved}}79}80 81} // namespace Example182 83namespace Example2 {84 85template <bool B> struct X {86 static constexpr int f(short) requires B {87 return 42;88 }89 static constexpr int f(short) {90 return 24;91 }92};93 94template <typename T>95constexpr int f(T) { return 1; }96 97template <typename T>98 requires __is_same(T, int)99constexpr int f(T) { return 2; }100 101void test() {102 constexpr auto x = &X<true>::f;103 static_assert(__is_same(decltype(x), int(*const)(short)), "");104 static_assert(x(0) == 42, "");105 106 constexpr auto y = &X<false>::f;107 static_assert(__is_same(decltype(y), int(*const)(short)));108 static_assert(y(0) == 24, "");109 110 constexpr auto z = &f<int>;111 static_assert(__is_same(decltype(z), int(*const)(int)));112 static_assert(z(0) == 2, "");113 114 // C++ [temp.deduct.call]p6:115 // If the argument is an overload set containing one or more function templates,116 // the parameter is treated as a non-deduced context.117 auto w = f; // since-cxx20-error {{variable 'w' with type 'auto' has incompatible initializer of type '<overloaded function type>'}}118}119 120} // namespace Example2121#endif122 123#if __cplusplus >= 201103L124namespace Example3 {125 126template <typename T> void f(T &&, void (*)(T &&)); // #cwg2918_f127 128void g(int &);129inline namespace A {130void g(short &&);131}132inline namespace B {133void g(short &&);134}135 136void q() {137 int x;138 f(x, g);139 // since-cxx11-error@-1 {{no matching function for call to 'f'}}140 // since-cxx11-note@#cwg2918_f {{candidate template ignored: deduced conflicting types for parameter 'T' ('int &' vs. 'short')}}141}142 143} // namespace Example3144 145#endif146 147} // namespace cwg2918148 149#if __cplusplus > 202302L150namespace std {151 using size_t = decltype(sizeof(0));152} // namespace std153void *operator new(std::size_t, void *p) { return p; }154void* operator new[] (std::size_t, void* p) {return p; }155#endif156 157namespace cwg2922 { // cwg2922: 20158#if __cplusplus > 202302L159union U { int a, b; };160constexpr U nondeterministic(bool i) {161 if(i) {162 U u;163 new (&u) int(); // #cwg2922-placement-new164 return u;165 }166 return {};167}168constexpr U _ = nondeterministic(true);169// since-cxx26-error@-1 {{constexpr variable '_' must be initialized by a constant expression}}170// since-cxx26-note@#cwg2922-placement-new {{placement new would change type of storage from 'U' to 'int'}}171// since-cxx26-note@-3 {{in call to 'nondeterministic(true)'}}172#endif173} // namespace cwg2922174