249 lines · cpp
1// RUN: %clang_cc1 -std=c++98 -pedantic-errors %s -verify=expected,cxx98-142// RUN: %clang_cc1 -std=c++11 -pedantic-errors %s -verify=expected,cxx98-143// RUN: %clang_cc1 -std=c++14 -pedantic-errors %s -verify=expected,cxx98-144// RUN: %clang_cc1 -std=c++17 -pedantic-errors %s -verify=expected,since-cxx175// RUN: %clang_cc1 -std=c++20 -pedantic-errors %s -verify=expected,since-cxx20,since-cxx176// RUN: %clang_cc1 -std=c++23 -pedantic-errors %s -verify=expected,since-cxx20,since-cxx177// RUN: %clang_cc1 -std=c++2c -pedantic-errors %s -verify=expected,since-cxx20,since-cxx178 9namespace cwg2406 { // cwg2406: 510#if __cplusplus >= 201703L11void fallthrough(int n) {12 void g(), h(), i();13 switch (n) {14 case 1:15 case 2:16 g();17 [[fallthrough]];18 case 3: // warning on fallthrough discouraged19 do {20 [[fallthrough]];21 // since-cxx17-error@-1 {{fallthrough annotation does not directly precede switch label}}22 } while (false);23 case 6:24 do {25 [[fallthrough]];26 // since-cxx17-error@-1 {{fallthrough annotation does not directly precede switch label}}27 } while (n);28 case 7:29 while (false) {30 [[fallthrough]];31 // since-cxx17-error@-1 {{fallthrough annotation does not directly precede switch label}}32 }33 case 5:34 h();35 case 4: // implementation may warn on fallthrough36 i();37 [[fallthrough]];38 // since-cxx17-error@-1 {{fallthrough annotation does not directly precede switch label}}39 }40}41#endif42} // namespace cwg240643 44namespace cwg2428 { // cwg2428: 1945#if __cplusplus >= 202002L46template <typename>47concept C [[deprecated]] = true; // #cwg2428-C48 49template <typename>50[[deprecated]] concept C2 = true;51// since-cxx20-error@-1 {{expected unqualified-id}}52 53template <typename T>54concept C3 = C<T>;55// since-cxx20-warning@-1 {{'C' is deprecated}}56// since-cxx20-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}57 58template <typename T, C U>59// since-cxx20-warning@-1 {{'C' is deprecated}}60// since-cxx20-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}61requires C<T>62// since-cxx20-warning@-1 {{'C' is deprecated}}63// since-cxx20-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}64void f() {65 bool b = C<int>;66 // since-cxx20-warning@-1 {{'C' is deprecated}}67 // since-cxx20-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}68};69 70void g(C auto a) {};71// since-cxx20-warning@-1 {{'C' is deprecated}}72// since-cxx20-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}73 74template <typename T>75auto h() -> C auto {76// since-cxx20-warning@-1 {{'C' is deprecated}}77// since-cxx20-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}78 C auto foo = T();79 // since-cxx20-warning@-1 {{'C' is deprecated}}80 // since-cxx20-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}81 C auto *bar = T();82 // since-cxx20-warning@-1 {{'C' is deprecated}}83 // since-cxx20-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}84 C auto &baz = T();85 // since-cxx20-warning@-1 {{'C' is deprecated}}86 // since-cxx20-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}87 C auto &&quux = T();88 // since-cxx20-warning@-1 {{'C' is deprecated}}89 // since-cxx20-note@#cwg2428-C {{'C' has been explicitly marked deprecated here}}90 return foo;91}92#endif93} // namespace cwg242894 95namespace cwg2430 { // cwg2430: 2.796struct S {97 S f(S s) { return s; }98};99} // namespace cwg2430100 101namespace cwg2450 { // cwg2450: 18102#if __cplusplus >= 202302L103struct S {int a;};104template <S s>105void f(){}106 107void test() {108f<{0}>();109f<{.a= 0}>();110}111 112#endif113} // namespace cwg2450114 115namespace cwg2459 { // cwg2459: 18116#if __cplusplus >= 202302L117struct A {118 constexpr A(float) {}119};120template<A> struct X {};121X<1> x;122#endif123} // namespace cwg2459124 125namespace cwg2445 { // cwg2445: 19126#if __cplusplus >= 202002L127 template <typename> constexpr bool F = false;128 template <typename T> struct A { };129 130 template <typename T, typename U>131 bool operator==(T, A<U *>);132 133 template <typename T, typename U>134 bool operator!=(A<T>, U) {135 static_assert(F<T>, "Isn't this less specialized?");136 return false;137 }138 139 bool f(A<int> ax, A<int *> ay) { return ay != ax; }140 141 template<class T> concept AlwaysTrue=true;142 template <class T> struct B {143 template <AlwaysTrue U>144 bool operator==(const B<U>&)const;145 };146 147 148 template <typename U>149 bool operator==(const B<int>&,const B<U>&) {150 static_assert(F<int>, "Isn't this less specialized?");151 return false;152 }153 154 bool g(B<int> bx, B<int *> by) { return bx == by; }155 156 struct C{157 template<AlwaysTrue T>158 int operator+(T){return 0;}159 template<class T>160 void operator-(T){}161 };162 template<class T>163 void operator+(C&&,T){}164 template<AlwaysTrue T>165 int operator-(C&&,T){return 0;}166 167 void t(int* iptr){168 int x1 = C{} + iptr;169 int x2 = C{} - iptr;170 }171 172 struct D{173 template<AlwaysTrue T>174 int operator+(T) volatile {return 1;}175 };176 177 template<class T>178 void operator+(volatile D&,T) {}179 180 int foo(volatile D& d){181 return d + 1;182 }183#endif184} // namespace cwg2445185 186namespace cwg2486 { // cwg2486: 4 c++17187struct C {188 void fn() throw();189};190 191static void call(C& c, void (C::*f)()) {192 (c.*f)();193}194 195static void callNE(C& c, void (C::*f)() throw()) {196// cxx98-14-warning@-1 {{mangled name of 'callNE' will change in C++17 due to non-throwing exception specification in function signature}}197 (c.*f)();198}199 200void ref() {201 C c;202 call(c, &C::fn); // <= implicit cast removes noexcept203 callNE(c, &C::fn);204}205 206void (*p)();207void (*pp)() throw() = p;208// since-cxx17-error@-1 {{cannot initialize a variable of type 'void (*)() throw()' with an lvalue of type 'void (*)()': different exception specifications}}209 210struct S {211 typedef void (*p)();212 operator p(); // #cwg2486-conv213};214void (*q)() throw() = S();215// since-cxx17-error@-1 {{no viable conversion from 'S' to 'void (*)() throw()'}}216// since-cxx17-note@#cwg2486-conv {{candidate function}}217} // namespace cwg2486218 219 220namespace cwg2496 { // cwg2496: 21221#if __cplusplus >= 201102L222struct S {223 virtual void f(); // #cwg2496-f224 virtual void g() &; // #cwg2496-g225 virtual void h(); // #cwg2496-h226 virtual void i();227 virtual void j() &;228 virtual void k() &&;229 virtual void l() &;230};231 232struct T : S {233 virtual void f() &;234 // expected-error@-1 {{cannot overload a member function with ref-qualifier '&' with a member function without a ref-qualifier}}235 // expected-note@#cwg2496-f {{previous declaration is here}}236 virtual void g();237 // expected-error@-1 {{cannot overload a member function without a ref-qualifier with a member function with ref-qualifier '&'}}238 // expected-note@#cwg2496-g {{previous declaration is here}}239 virtual void h() &&;240 // expected-error@-1 {{cannot overload a member function with ref-qualifier '&&' with a member function without a ref-qualifier}}241 // expected-note@#cwg2496-h {{previous declaration is here}}242 virtual void i();243 virtual void j() &;244 virtual void k() &;245 virtual void l() &&;246};247#endif248}249