xref: /llvm-project/clang/test/CXX/drs/cwg2xx.cpp (revision 10fb5d2b4be54c779eda80b65a737b9dae2d959b)
1 // RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11,cxx98-11,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11,since-cxx14,cxx98-14,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,cxx98-17 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors
7 // RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx14,since-cxx17,since-cxx20 -fexceptions -fcxx-exceptions -pedantic-errors
8 
9 // FIXME: diagnostic above is emitted only on Windows platforms
10 // PR13819 -- __SIZE_TYPE__ is incompatible.
11 typedef __SIZE_TYPE__ size_t;
12 // cxx98-error@-1 0-1 {{'long long' is a C++11 extension}}
13 
14 #if __cplusplus == 199711L
15 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
16 // cxx98-error@-1 {{variadic macros are a C99 feature}}
17 #endif
18 
19 #if __cplusplus == 199711L
20 #define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x))
21 #else
22 #define __enable_constant_folding
23 #endif
24 
25 namespace cwg200 { // cwg200: dup 214
26   template <class T> T f(int);
27   template <class T, class U> T f(U) = delete;
28   // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
29 
30   void g() {
31     f<int>(1);
32   }
33 } // namespace cwg200
34 
35 // cwg201 is in cwg201.cpp
36 
37 namespace cwg202 { // cwg202: 3.1
38   template<typename T> T f();
39   template<int (*g)()> struct X {
40     static_assert(__enable_constant_folding(g == &f<int>), "");
41   };
42   template struct X<f>;
43 } // namespace cwg202
44 
45 namespace cwg203 { // cwg203: 3.0
46 namespace ex1 {
47 struct B {
48   int i;
49 };
50 struct D1 : B {};
51 struct D2 : B {};
52 
53 int(D1::*pmD1) = &D2::i;
54 } // namespace ex1
55 
56 #if __cplusplus >= 202002L
57 namespace ex2 {
58 struct A {
59   int i;
60   virtual void f() = 0; // #cwg203-ex2-A-f
61 };
62 
63 struct B : A {
64   int j;
65   constexpr B() : j(5) {}
66   virtual void f();
67 };
68 
69 struct C : B {
70   constexpr C() { j = 10; }
71 };
72 
73 template <class T>
74 constexpr int DefaultValue(int(T::*m)) {
75   return T().*m;
76   // since-cxx20-error@-1 {{allocating an object of abstract class type 'cwg203::ex2::A'}}
77   //   since-cxx20-note@#cwg203-ex2-a {{in instantiation of function template specialization 'cwg203::ex2::DefaultValue<cwg203::ex2::A>' requested here}}
78   //   since-cxx20-note@#cwg203-ex2-A-f {{unimplemented pure virtual method 'f' in 'A'}}
79 } // #cwg203-ex2-DefaultValue
80 
81 int a = DefaultValue(&B::i); // #cwg203-ex2-a
82 static_assert(DefaultValue(&C::j) == 5, "");
83 } // namespace ex2
84 #endif
85 
86 namespace ex3 {
87 class Base {
88 public:
89   int func() const;
90 };
91 
92 class Derived : public Base {};
93 
94 template <class T> class Templ { // #cwg203-ex3-Templ
95 public:
96   template <class S> Templ(S (T::*ptmf)() const); // #cwg203-ex3-Templ-ctor
97 };
98 
99 void foo() { Templ<Derived> x(&Derived::func); }
100 // expected-error@-1 {{no matching constructor for initialization of 'Templ<Derived>'}}
101 //   expected-note@#cwg203-ex3-Templ {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int (cwg203::ex3::Base::*)() const' to 'const Templ<Derived>' for 1st argument}}
102 //   since-cxx11-note@#cwg203-ex3-Templ {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int (cwg203::ex3::Base::*)() const' to 'Templ<Derived>' for 1st argument}}
103 //   expected-note@#cwg203-ex3-Templ-ctor {{candidate template ignored: could not match 'cwg203::ex3::Derived' against 'cwg203::ex3::Base'}}
104 } // namespace ex3
105 
106 namespace ex4 {
107 struct Very_base {
108   int a;
109 };
110 struct Base1 : Very_base {};
111 struct Base2 : Very_base {};
112 struct Derived : Base1, Base2 {
113 };
114 
115 int f() {
116   Derived d;
117   // FIXME: in the diagnostic below, Very_base is fully qualified, but Derived is not
118   int Derived::*a_ptr = &Derived::Base1::a;
119   /* expected-error@-1
120   {{ambiguous conversion from pointer to member of base class 'cwg203::ex4::Very_base' to pointer to member of derived class 'Derived':
121     struct cwg203::ex4::Derived -> Base1 -> Very_base
122     struct cwg203::ex4::Derived -> Base2 -> Very_base}}*/
123 }
124 } // namespace ex4
125 
126 namespace ex5 {
127 struct Base {
128   int a;
129 };
130 struct Derived : Base {
131   int b;
132 };
133 
134 template <typename Class, typename Member_type, Member_type Base::*ptr>
135 Member_type get(Class &c) {
136   return c.*ptr;
137 }
138 
139 void call(int (*f)(Derived &)); // #cwg203-ex5-call
140 
141 int f() {
142   // ill-formed, contrary to Core issue filing:
143   // `&Derived::b` yields `int Derived::*`, which can't initialize NTTP of type `int Base::*`,
144   // because (implicit) pointer-to-member conversion doesn't upcast.
145   call(&get<Derived, int, &Derived::b>);
146   // expected-error@-1 {{no matching function for call to 'call'}}
147   //   expected-note@#cwg203-ex5-call {{candidate function not viable: no overload of 'get' matching 'int (*)(Derived &)' for 1st argument}}
148 
149   // well-formed, contrary to Core issue filing:
150   // `&Derived::a` yields `int Base::*`,
151   // which can initialize NTTP of type `int Base::*`.
152   call(&get<Derived, int, &Derived::a>);
153 
154   call(&get<Base, int, &Derived::a>);
155   // expected-error@-1 {{no matching function for call to 'call'}}
156   //   expected-note@#cwg203-ex5-call {{candidate function not viable: no overload of 'get' matching 'int (*)(Derived &)' for 1st argument}}
157 }
158 } // namespace ex5
159 
160 namespace ex6 {
161 struct Base {
162   int a;
163 };
164 struct Derived : private Base { // #cwg203-ex6-Derived
165 public:
166   using Base::a; // make `a` accessible
167 };
168 
169 int f() {
170   Derived d;
171   int b = d.a;
172   // FIXME: in the diagnostic below, Base is fully qualified, but Derived is not
173   int Derived::*ptr = &Derived::a;
174   // expected-error@-1 {{cannot cast private base class 'cwg203::ex6::Base' to 'Derived'}}
175   //   expected-note@#cwg203-ex6-Derived {{declared private here}}
176 }
177 } // namespace ex6
178 } // namespace cwg203
179 
180 // cwg204: sup 820
181 
182 namespace cwg206 { // cwg206: 2.7
183   struct S; // #cwg206-S
184   template<typename T> struct Q { S s; };
185   // expected-error@-1 {{field has incomplete type 'S'}}
186   //   expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}}
187   template<typename T> void f() { S s; }
188   // expected-error@-1 {{variable has incomplete type 'S'}}
189   //   expected-note@#cwg206-S {{forward declaration of 'cwg206::S'}}
190 } // namespace cwg206
191 
192 namespace cwg207 { // cwg207: 2.7
193   class A {
194   protected:
195     static void f() {}
196   };
197   class B : A {
198   public:
199     using A::f;
200     void g() {
201       A::f();
202       f();
203     }
204   };
205 } // namespace cwg207
206 
207 // cwg208 FIXME: write codegen test
208 
209 namespace cwg209 { // cwg209: 3.2
210   class A {
211     void f(); // #cwg209-A-f
212   };
213   class B {
214     friend void A::f();
215     // expected-error@-1 {{friend function 'f' is a private member of 'cwg209::A'}}
216     //   expected-note@#cwg209-A-f {{implicitly declared private here}}
217   };
218 } // namespace cwg209
219 
220 // cwg210 is in cwg210.cpp
221 
222 namespace cwg211 { // cwg211: 2.7
223   struct A {
224     A() try {
225       throw 0;
226     } catch (...) {
227       return;
228       // expected-error@-1 {{return in the catch of a function try block of a constructor is illegal}}
229     }
230   };
231 } // namespace cwg211
232 
233 namespace cwg213 { // cwg213: 2.7
234   template <class T> struct A : T {
235     void h(T t) {
236       char &r1 = f(t);
237       int &r2 = g(t);
238       // expected-error@-1 {{explicit qualification required to use member 'g' from dependent base class}}
239       //   expected-note@#cwg213-instantiation {{in instantiation of member function 'cwg213::A<cwg213::B>::h' requested here}}
240       //   expected-note@#cwg213-B-g {{member is declared here}}
241     }
242   };
243   struct B {
244     int &f(B);
245     int &g(B); // #cwg213-B-g
246   };
247   char &f(B);
248 
249   template void A<B>::h(B); // #cwg213-instantiation
250 } // namespace cwg213
251 
252 namespace cwg214 { // cwg214: 2.7
253   template<typename T, typename U> T checked_cast(U from) { U::error; }
254   template<typename T, typename U> T checked_cast(U *from);
255   class C {};
256   void foo(int *arg) { checked_cast<const C *>(arg); }
257 
258   template<typename T> T f(int);
259   template<typename T, typename U> T f(U) { T::error; }
260   void g() {
261     f<int>(1);
262   }
263 } // namespace cwg214
264 
265 namespace cwg215 { // cwg215: 2.9
266   template<typename T> class X {
267     friend void T::foo();
268     int n;
269   };
270   struct Y {
271     void foo() { (void)+X<Y>().n; }
272   };
273 } // namespace cwg215
274 
275 namespace cwg216 { // cwg216: no
276   // FIXME: Should reject this: 'f' has linkage but its type does not,
277   // and 'f' is odr-used but not defined in this TU.
278   typedef enum { e } *E;
279   void f(E);
280   void g(E e) { f(e); }
281 
282   struct S {
283     // FIXME: Should reject this: 'f' has linkage but its type does not,
284     // and 'f' is odr-used but not defined in this TU.
285     typedef enum { e } *E;
286     void f(E);
287   };
288   void g(S s, S::E e) { s.f(e); }
289 } // namespace cwg216
290 
291 namespace cwg217 { // cwg217: 2.7
292   template<typename T> struct S {
293     void f(int);
294   };
295   template<typename T> void S<T>::f(int = 0) {}
296   // expected-error@-1 {{default arguments cannot be added to an out-of-line definition of a member of a class template}}
297 } // namespace cwg217
298 
299 namespace cwg218 { // cwg218: 2.7
300                   // NB: also dup 405
301   namespace A {
302     struct S {};
303     void f(S);
304   }
305   namespace B {
306     struct S {};
307     void f(S);
308   }
309 
310   struct C {
311     int f;
312     void test1(A::S as) { f(as); }
313     // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
314     void test2(A::S as) { void f(); f(as); }
315     // expected-error@-1 {{too many arguments to function call, expected 0, have 1}}
316     //   expected-note@-2 {{'f' declared here}}
317     void test3(A::S as) { using A::f; f(as); } // ok
318     void test4(A::S as) { using B::f; f(as); } // ok
319     void test5(A::S as) { int f; f(as); }
320     // expected-error@-1 {{called object type 'int' is not a function or function pointer}}
321     void test6(A::S as) { struct f {}; (void) f(as); }
322     // expected-error@-1 {{no matching conversion for functional-style cast from 'A::S' to 'f'}}
323     //   expected-note@-2 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A::S' to 'const f' for 1st argument}}
324     //   since-cxx11-note@-3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A::S' to 'f' for 1st argument}}
325     //   expected-note@-4 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
326   };
327 
328   namespace D {
329     struct S {};
330     struct X { void operator()(S); } f;
331   }
332   void testD(D::S ds) { f(ds); }
333   // expected-error@-1 {{use of undeclared identifier 'f'}}
334 
335   namespace E {
336     struct S {};
337     struct f { f(S); };
338   }
339   void testE(E::S es) { f(es); }
340   // expected-error@-1 {{use of undeclared identifier 'f'}}
341 
342   namespace F {
343     struct S {
344       template<typename T> friend void f(S, T) {}
345     };
346   }
347   void testF(F::S fs) { f(fs, 0); }
348 
349   namespace G {
350     namespace X {
351       int f;
352       struct A {};
353     }
354     namespace Y {
355       template<typename T> void f(T);
356       struct B {};
357     }
358     template<typename A, typename B> struct C {};
359   }
360   void testG(G::C<G::X::A, G::Y::B> gc) { f(gc); }
361 } // namespace cwg218
362 
363 // cwg219: na
364 // cwg220: na
365 
366 namespace cwg221 { // cwg221: 3.6
367   struct A { // #cwg221-S
368     A &operator=(int&); // #cwg221-S-copy-assign
369     A &operator+=(int&);
370     static A &operator=(A&, double&);
371     // expected-error@-1 {{overloaded 'operator=' cannot be a static member function}}
372     static A &operator+=(A&, double&);
373     // expected-error@-1 {{overloaded 'operator+=' cannot be a static member function}}
374     friend A &operator=(A&, char&);
375     // expected-error@-1 {{overloaded 'operator=' must be a non-static member function}}
376     friend A &operator+=(A&, char&);
377   };
378   A &operator=(A&, float&);
379   // expected-error@-1 {{overloaded 'operator=' must be a non-static member function}}
380   A &operator+=(A&, float&);
381 
382   void test(A a, int n, char c, float f) {
383     a = n;
384     a += n;
385     a = c;
386     // expected-error@-1 {{no viable overloaded '='}}
387     //   expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'char' to 'int &' for 1st argument}}
388     //   since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'char' to 'A' for 1st argument}}
389     //   expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'char' to 'const A' for 1st argument}}
390     a += c;
391     a = f;
392     // expected-error@-1 {{no viable overloaded '='}}
393     //   expected-note@#cwg221-S-copy-assign {{candidate function not viable: no known conversion from 'float' to 'int &' for 1st argument}}
394     //   since-cxx11-note@#cwg221-S {{candidate function (the implicit move assignment operator) not viable: no known conversion from 'float' to 'A' for 1st argument}}
395     //   expected-note@#cwg221-S {{candidate function (the implicit copy assignment operator) not viable: no known conversion from 'float' to 'const A' for 1st argument}}
396     a += f;
397   }
398 } // namespace cwg221
399 
400 namespace cwg222 { // cwg222: dup 637
401   void f(int a, int b, int c, int *x) {
402 #pragma clang diagnostic push
403 #pragma clang diagnostic warning "-Wunsequenced"
404     void((a += b) += c);
405     void((a += b) + (a += c));
406     // expected-warning@-1 {{multiple unsequenced modifications to 'a'}}
407 
408     x[a++] = a;
409     // cxx98-14-warning@-1 {{unsequenced modification and access to 'a'}}
410 
411     a = b = 0; // ok, read and write of 'b' are sequenced
412 
413     a = (b = a++);
414     // cxx98-14-warning@-1 {{multiple unsequenced modifications to 'a'}}
415     a = (b = ++a);
416 #pragma clang diagnostic pop
417   }
418 } // namespace cwg222
419 
420 // cwg223: na
421 
422 namespace cwg224 { // cwg224: 16
423   namespace example1 {
424     template <class T> class A {
425       typedef int type;
426       A::type a;
427       A<T>::type b;
428       A<T*>::type c;
429       // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::type; implicit 'typename' is a C++20 extension}}
430       ::cwg224::example1::A<T>::type d;
431 
432       class B {
433         typedef int type;
434 
435         A::type a;
436         A<T>::type b;
437         A<T*>::type c;
438         // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::type; implicit 'typename' is a C++20 extension}}
439         ::cwg224::example1::A<T>::type d;
440 
441         B::type e;
442         A<T>::B::type f;
443         A<T*>::B::type g;
444         // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T *>::B::type; implicit 'typename' is a C++20 extension}}
445         typename A<T*>::B::type h;
446       };
447     };
448 
449     template <class T> class A<T*> {
450       typedef int type;
451       A<T*>::type a;
452       A<T>::type b;
453       // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name A<T>::type; implicit 'typename' is a C++20 extension}}
454     };
455 
456     template <class T1, class T2, int I> struct B {
457       typedef int type;
458       B<T1, T2, I>::type b1;
459       B<T2, T1, I>::type b2;
460       // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<T2, T1, I>::type; implicit 'typename' is a C++20 extension}}
461 
462       typedef T1 my_T1;
463       static const int my_I = I;
464       static const int my_I2 = I+0;
465       static const int my_I3 = my_I;
466       B<my_T1, T2, my_I>::type b3;
467       // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<my_T1, T2, my_I>::type; implicit 'typename' is a C++20 extension}}
468       B<my_T1, T2, my_I2>::type b4;
469       // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<my_T1, T2, my_I2>::type; implicit 'typename' is a C++20 extension}}
470       B<my_T1, T2, my_I3>::type b5;
471       // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name B<my_T1, T2, my_I3>::type; implicit 'typename' is a C++20 extension}}
472     };
473   }
474 
475   namespace example2 {
476     template <int, typename T> struct X { typedef T type; };
477     template <class T> class A {
478       static const int i = 5;
479       X<i, int>::type w;
480       X<A::i, char>::type x;
481       X<A<T>::i, double>::type y;
482       X<A<T*>::i, long>::type z;
483       // cxx98-17-error@-1 {{missing 'typename' prior to dependent type name X<A<T *>::i, long>::type; implicit 'typename' is a C++20 extension}}
484       int f();
485     };
486     template <class T> int A<T>::f() {
487       return i;
488     }
489   }
490 } // namespace cwg224
491 
492 // cwg225: yes
493 template<typename T> void cwg225_f(T t) { cwg225_g(t); }
494 // expected-error@-1 {{call to function 'cwg225_g' that is neither visible in the template definition nor found by argument-dependent lookup}}
495 //   expected-note@#cwg225-f {{in instantiation of function template specialization 'cwg225_f<int>' requested here}}
496 //   expected-note@#cwg225-g {{'cwg225_g' should be declared prior to the call site}}
497 void cwg225_g(int); // #cwg225-g
498 template void cwg225_f(int); // #cwg225-f
499 
500 namespace cwg226 { // cwg226: no
501   // FIXME: This appears to be wrong: default arguments for function templates
502   // are listed as a defect (in c++98) not an extension. EDG accepts them in
503   // strict c++98 mode.
504   template<typename T = void> void f() {}
505   // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
506   template<typename T> struct S {
507     template<typename U = void> void g();
508     // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
509     template<typename U> struct X;
510     template<typename U> void h();
511   };
512   template<typename T> template<typename U> void S<T>::g() {}
513   template<typename T> template<typename U = void> struct S<T>::X {};
514   // expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}}
515   template<typename T> template<typename U = void> void S<T>::h() {}
516   // expected-error@-1 {{cannot add a default template argument to the definition of a member of a class template}}
517 
518   template<typename> void friend_h();
519   struct A {
520     // FIXME: This is ill-formed.
521     template<typename=void> struct friend_B;
522     // FIXME: f, h, and i are ill-formed.
523     //  f is ill-formed because it is not a definition.
524     //  h and i are ill-formed because they are not the only declarations of the
525     //  function in the translation unit.
526     template<typename=void> void friend_f();
527     // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
528     template<typename=void> void friend_g() {}
529     // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
530     template<typename=void> void friend_h() {}
531     // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
532     template<typename=void> void friend_i() {}
533     // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
534   };
535   template<typename> void friend_i();
536 
537   template<typename=void, typename X> void foo(X) {}
538   // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
539   template<typename=void, typename X> struct Foo {};
540   // expected-error@-1 {{template parameter missing a default argument}}
541   //   expected-note@-2 {{previous default template argument defined here}}
542 
543   template<typename=void, typename X, typename, typename Y> int foo(X, Y);
544   // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
545   template<typename, typename X, typename=void, typename Y> int foo(X, Y);
546   // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
547   int x = foo(0, 0);
548 } // namespace cwg226
549 
550 namespace cwg227 { // cwg227: 2.7
551 void f(bool b) {
552   if (b)
553     int n;
554   else
555     int n;
556 }
557 } // namespace cwg227
558 
559 namespace cwg228 { // cwg228: 2.7
560   template <class T> struct X {
561     void f();
562   };
563   template <class T> struct Y {
564     void g(X<T> x) { x.template X<T>::f(); }
565   };
566 } // namespace cwg228
567 
568 namespace cwg229 { // cwg229: 2.9
569   template<typename T> void f();
570   template<typename T> void f<T*>() {}
571   // expected-error@-1 {{function template partial specialization is not allowed}}
572   template<> void f<int>() {}
573 } // namespace cwg229
574 
575 namespace cwg230 { // cwg230: 3.0
576   struct S {
577     S() { f(); }
578     // expected-warning@-1 {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'cwg230::S'}}
579     //   expected-note@#cwg230-f {{'f' declared here}}
580     virtual void f() = 0; // #cwg230-f
581   };
582 } // namespace cwg230
583 
584 namespace cwg231 { // cwg231: 2.7
585   namespace outer {
586     namespace inner {
587       int i; // #cwg231-i
588     }
589     void f() { using namespace inner; }
590     int j = i;
591     // expected-error@-1 {{use of undeclared identifier 'i'; did you mean 'inner::i'?}}
592     //   expected-note@#cwg231-i {{'inner::i' declared here}}
593   }
594 } // namespace cwg231
595 
596 // cwg234: na
597 // cwg235: na
598 
599 namespace cwg236 { // cwg236: 3.2
600   void *p = int();
601   // cxx98-warning@-1 {{expression which evaluates to zero treated as a null pointer constant of type 'void *'}}
602   // since-cxx11-error@-2 {{cannot initialize a variable of type 'void *' with an rvalue of type 'int'}}
603 } // namespace cwg236
604 
605 namespace cwg237 { // cwg237: dup 470
606   template<typename T> struct A { void f() { T::error; } };
607   template<typename T> struct B : A<T> {};
608   template struct B<int>; // ok
609 } // namespace cwg237
610 
611 namespace cwg239 { // cwg239: 2.7
612   namespace NS {
613     class T {};
614     void f(T);
615     float &g(T, int);
616   }
617   NS::T parm;
618   int &g(NS::T, float);
619   int main() {
620     f(parm);
621     float &r = g(parm, 1);
622     extern int &g(NS::T, float);
623     int &s = g(parm, 1);
624   }
625 } // namespace cwg239
626 
627 // cwg240: dup 616
628 
629 namespace cwg241 { // cwg241: 9
630   namespace A {
631     struct B {};
632     template <int X> void f(); // #cwg241-A-f
633     template <int X> void g(B);
634   }
635   namespace C {
636     template <class T> void f(T t); // #cwg241-C-f
637     template <class T> void g(T t); // #cwg241-C-g
638   }
639   void h(A::B b) {
640     f<3>(b);
641     // expected-error@-1 {{no matching function for call to 'f'}}
642     //   expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
643     // cxx98-17-error@-3 {{use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension}}
644     g<3>(b);
645     // cxx98-17-error@-1 {{use of function template name with no prior declaration in function call with explicit template arguments is a C++20 extension}}
646     A::f<3>(b);
647     // expected-error@-1 {{no matching function for call to 'f'}}
648     //   expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
649     A::g<3>(b);
650     C::f<3>(b);
651     // expected-error@-1 {{no matching function for call to 'f'}}
652     //   expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
653     C::g<3>(b);
654     // expected-error@-1 {{no matching function for call to 'g'}}
655     //   expected-note@#cwg241-C-g {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
656     using C::f;
657     using C::g;
658     f<3>(b);
659     // expected-error@-1 {{no matching function for call to 'f'}}
660     //   expected-note@#cwg241-C-f {{candidate template ignored: invalid explicitly-specified argument for template parameter 'T'}}
661     //   expected-note@#cwg241-A-f {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
662     g<3>(b);
663   }
664 } // namespace cwg241
665 
666 namespace cwg243 { // cwg243: 2.8
667   struct B;
668   struct A {
669     A(B); // #cwg243-A
670   };
671   struct B {
672     operator A() = delete; // #cwg243-B
673     // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
674   } b;
675   A a1(b);
676   A a2 = b;
677   // expected-error@-1 {{conversion from 'struct B' to 'A' is ambiguous}}
678   //   expected-note@#cwg243-A {{candidate constructor}}
679   //   expected-note@#cwg243-B {{candidate function has been explicitly deleted}}
680 } // namespace cwg243
681 
682 namespace cwg244 { // cwg244: 11
683                   // NB: this test is reused by cwg399
684   struct B {}; // #cwg244-B
685   struct D : B {};
686 
687   D D_object;
688   typedef B B_alias;
689   B* B_ptr = &D_object;
690 
691   void f() {
692     D_object.~B();
693     // expected-error@-1 {{destructor type 'cwg244::B' in object destruction expression does not match the type 'D' of the object being destroyed}}
694     //   expected-note@#cwg244-B {{type 'cwg244::B' found by destructor name lookup}}
695     D_object.B::~B();
696     D_object.D::~B(); // FIXME: Missing diagnostic for this.
697     B_ptr->~B();
698     B_ptr->~B_alias();
699     B_ptr->B_alias::~B();
700     B_ptr->B_alias::~B_alias();
701     B_ptr->cwg244::~B();
702     // expected-error@-1 {{no member named '~B' in namespace 'cwg244'}}
703     B_ptr->cwg244::~B_alias();
704     // expected-error@-1 {{no member named '~B' in namespace 'cwg244'}}
705   }
706 
707   template<typename T, typename U>
708   void f(T *B_ptr, U D_object) {
709     D_object.~B(); // FIXME: Missing diagnostic for this.
710     D_object.B::~B();
711     D_object.D::~B(); // FIXME: Missing diagnostic for this.
712     B_ptr->~B();
713     B_ptr->~B_alias();
714     B_ptr->B_alias::~B();
715     B_ptr->B_alias::~B_alias();
716     B_ptr->cwg244::~B();
717     // expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
718     B_ptr->cwg244::~B_alias();
719     // expected-error@-1 {{'cwg244' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
720   }
721   template void f<B, D>(B*, D);
722 
723   namespace N {
724     template<typename T> struct E {};
725     typedef E<int> F;
726   }
727   void g(N::F f) {
728     typedef N::F G; // #cwg244-G
729     f.~G();
730     f.G::~E();
731     // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
732     f.G::~F();
733     // expected-error@-1 {{undeclared identifier 'F' in destructor name}}
734     f.G::~G();
735     // This is technically ill-formed; E is looked up in 'N::' and names the
736     // class template, not the injected-class-name of the class. But that's
737     // probably a bug in the standard.
738     f.N::F::~E();
739     // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
740     // This is valid; we look up the second F in the same scope in which we
741     // found the first one, that is, 'N::'.
742     f.N::F::~F();
743     // This is technically ill-formed; G is looked up in 'N::' and is not found.
744     // Rejecting this seems correct, but most compilers accept, so we do also.
745     f.N::F::~G();
746     // expected-error@-1 {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}
747     //   expected-note@#cwg244-G {{type 'G' (aka 'E<int>') found by destructor name lookup}}
748   }
749 
750   // Bizarrely, compilers perform lookup in the scope for qualified destructor
751   // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
752   // this.
753   namespace QualifiedLookupInScope {
754     namespace N {
755       template <typename> struct S { struct Inner {}; };
756     }
757     template <typename U> void f(typename N::S<U>::Inner *p) {
758       typedef typename N::S<U>::Inner T;
759       p->::cwg244::QualifiedLookupInScope::N::S<U>::Inner::~T();
760       // expected-error@-1 {{no type named 'T' in 'cwg244::QualifiedLookupInScope::N::S<int>'}}
761       //   expected-note@#cwg244-f {{in instantiation of function template specialization 'cwg244::QualifiedLookupInScope::f<int>' requested here}}
762     }
763     template void f<int>(N::S<int>::Inner *); // #cwg244-f
764 
765     template <typename U> void g(U *p) {
766       typedef U T;
767       p->T::~T();
768       p->U::~T();
769       p->::cwg244::QualifiedLookupInScope::N::S<int>::Inner::~T();
770       // expected-error@-1 {{'T' does not refer to a type name in pseudo-destructor expression; expected the name of type 'U'}}
771     }
772     template void g(N::S<int>::Inner *);
773   }
774 } // namespace cwg244
775 
776 namespace cwg245 { // cwg245: 2.8
777   struct S {
778     enum E {}; // #cwg245-E
779     class E *p;
780     // expected-error@-1 {{use of 'E' with tag type that does not match previous declaration}}
781     //   expected-note@#cwg245-E {{previous use is here}}
782   };
783 } // namespace cwg245
784 
785 namespace cwg246 { // cwg246: 3.2
786   struct S {
787     S() try { // #cwg246-try
788       throw 0;
789 X: ;
790     } catch (int) {
791       goto X;
792       // expected-error@-1 {{cannot jump from this goto statement to its label}}
793       //   expected-note@#cwg246-try {{jump bypasses initialization of try block}}
794     }
795   };
796 } // namespace cwg246
797 
798 namespace cwg247 { // cwg247: 2.7
799   struct A {};
800   struct B : A {
801     void f();
802     void f(int);
803   };
804   void (A::*f)() = (void (A::*)())&B::f;
805 
806   struct C {
807     void f();
808     void f(int);
809   };
810   struct D : C {};
811   void (C::*g)() = &D::f;
812   void (D::*h)() = &D::f;
813 
814   struct E {
815     void f();
816   };
817   struct F : E {
818     using E::f;
819     void f(int);
820   };
821   void (F::*i)() = &F::f;
822 } // namespace cwg247
823 
824 namespace cwg248 { // cwg248: sup P1949
825   int \u040d\u040e = 0;
826 } // namespace cwg248
827 
828 namespace cwg249 { // cwg249: 2.7
829   template<typename T> struct X { void f(); };
830   template<typename T> void X<T>::f() {}
831 } // namespace cwg249
832 
833 namespace cwg250 { // cwg250: 2.7
834   typedef void (*FPtr)(double x[]);
835 
836   template<int I> void f(double x[]);
837   FPtr fp = &f<3>;
838 
839   template<int I = 3> void g(double x[]);
840   // cxx98-error@-1 {{default template arguments for a function template are a C++11 extension}}
841   FPtr gp = &g<>;
842 } // namespace cwg250
843 
844 namespace cwg252 { // cwg252: 3.1
845   struct A {
846     void operator delete(void*); // #cwg252-A
847   };
848   struct B {
849     void operator delete(void*); // #cwg252-B
850   };
851   struct C : A, B {
852     virtual ~C();
853   };
854   C::~C() {}
855   // expected-error@-1 {{member 'operator delete' found in multiple base classes of different types}}
856   //   expected-note@#cwg252-A {{member found by ambiguous name lookup}}
857   //   expected-note@#cwg252-B {{member found by ambiguous name lookup}}
858 
859   struct D {
860     void operator delete(void*, int); // #cwg252-D
861     virtual ~D();
862   };
863   D::~D() {}
864   // expected-error@-1 {{no suitable member 'operator delete' in 'D'}}
865   //   expected-note@#cwg252-D {{member 'operator delete' declared here}}
866 
867   struct E {
868     void operator delete(void*, int);
869     void operator delete(void*) = delete; // #cwg252-E
870     // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
871     virtual ~E();
872   };
873   E::~E() {}
874   // expected-error@-1 {{attempt to use a deleted function}}
875   //   expected-note@#cwg252-E {{'operator delete' has been explicitly marked deleted here}}
876 
877   struct F {
878     // If both functions are available, the first one is a placement delete.
879     void operator delete(void*, size_t);
880     void operator delete(void*) = delete; // #cwg252-F
881     // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
882     virtual ~F();
883   };
884   F::~F() {}
885   // expected-error@-1 {{attempt to use a deleted function}}
886   //   expected-note@#cwg252-F {{'operator delete' has been explicitly marked deleted here}}
887 
888   struct G {
889     void operator delete(void*, size_t);
890     virtual ~G();
891   };
892   G::~G() {}
893 } // namespace cwg252
894 
895 namespace cwg254 { // cwg254: 2.9
896   template<typename T> struct A {
897     typedef typename T::type type; // ok even if this is a typedef-name, because
898                                    // it's not an elaborated-type-specifier
899     typedef struct T::type foo;
900     // expected-error@-1 {{typedef 'type' cannot be referenced with the 'struct' specifier}}
901     //   expected-note@#cwg254-instantiation {{in instantiation of template class 'cwg254::A<cwg254::C>' requested here}}
902     //   expected-note@#cwg254-C {{declared here}}
903   };
904   struct B { struct type {}; };
905   struct C { typedef struct {} type; }; // #cwg254-C
906   A<B>::type n;
907   A<C>::type n; // #cwg254-instantiation
908 } // namespace cwg254
909 
910 namespace cwg255 { // cwg255: 2.7
911 struct S {
912   void operator delete(void *){}
913   void operator delete(void *, int){}
914 };
915 void f(S *p) { delete p; }
916 } // namespace cwg255
917 
918 // cwg256: dup 624
919 
920 namespace cwg257 { // cwg257: 3.4
921   struct A { A(int); }; // #cwg257-A
922   struct B : virtual A {
923     B() {}
924     virtual void f() = 0;
925   };
926   struct C : B {
927     C() {}
928   };
929   struct D : B {
930     D() {}
931     // expected-error@-1 {{constructor for 'cwg257::D' must explicitly initialize the base class 'A' which does not have a default constructor}}
932     //   expected-note@#cwg257-A {{'cwg257::A' declared here}}
933     void f();
934   };
935 } // namespace cwg257
936 
937 namespace cwg258 { // cwg258: 2.8
938   struct A {
939     void f(const int);
940     template<typename> void g(int);
941     float &h() const;
942   };
943   struct B : A {
944     using A::f;
945     using A::g;
946     using A::h;
947     int &f(int);
948     template<int> int &g(int); // #cwg258-B-g
949     int &h();
950   } b;
951   int &w = b.f(0);
952   int &x = b.g<int>(0);
953   // expected-error@-1 {{no matching member function for call to 'g'}}
954   //   expected-note@#cwg258-B-g {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
955   int &y = b.h();
956   float &z = const_cast<const B&>(b).h();
957 
958   struct C {
959     virtual void f(const int) = 0;
960   };
961   struct D : C {
962     void f(int);
963   } d;
964 
965   struct E {
966     virtual void f() = 0; // #cwg258-E-f
967   };
968   struct F : E {
969     void f() const {}
970   } f;
971   // expected-error@-1 {{variable type 'struct F' is an abstract class}}
972   //   expected-note@#cwg258-E-f {{unimplemented pure virtual method 'f' in 'F'}}
973 } // namespace cwg258
974 
975 namespace cwg259 { // cwg259: 4
976   template<typename T> struct A {};
977   template struct A<int>; // #cwg259-A-int
978   template struct A<int>;
979   // expected-error@-1 {{duplicate explicit instantiation of 'A<int>'}}
980   //   expected-note@#cwg259-A-int {{previous explicit instantiation is here}}
981 
982   template<> struct A<float>; // #cwg259-A-float
983   template struct A<float>;
984   // expected-warning@-1 {{explicit instantiation of 'A<float>' that occurs after an explicit specialization has no effect}}
985   //   expected-note@#cwg259-A-float {{previous template specialization is here}}
986 
987   template struct A<char>; // #cwg259-A-char
988   template<> struct A<char>;
989   // expected-error@-1 {{explicit specialization of 'cwg259::A<char>' after instantiation}}
990   //   expected-note@#cwg259-A-char {{explicit instantiation first required here}}
991 
992   template<> struct A<double>;
993   template<> struct A<double>;
994   template<> struct A<double> {}; // #cwg259-A-double
995   template<> struct A<double> {};
996   // expected-error@-1 {{redefinition of 'A<double>'}}
997   //   expected-note@#cwg259-A-double {{previous definition is here}}
998 
999   template<typename T> struct B; // #cwg259-B
1000   template struct B<int>;
1001   // expected-error@-1 {{explicit instantiation of undefined template 'cwg259::B<int>'}}
1002   //   expected-note@#cwg259-B {{template is declared here}}
1003 
1004   template<> struct B<float>; // #cwg259-B-float
1005   template struct B<float>;
1006   // expected-warning@-1 {{explicit instantiation of 'B<float>' that occurs after an explicit specialization has no effect}}
1007   //   expected-note@#cwg259-B-float {{previous template specialization is here}}
1008 } // namespace cwg259
1009 
1010 // FIXME: When cwg260 is resolved, also add tests for CWG507.
1011 
1012 namespace cwg261 { // cwg261: no
1013 #pragma clang diagnostic push
1014 #pragma clang diagnostic warning "-Wused-but-marked-unused"
1015 
1016   // FIXME: This is ill-formed, with a diagnostic required, because operator new
1017   // and operator delete are inline and odr-used, but not defined in this
1018   // translation unit.
1019   // We're also missing the -Wused-but-marked-unused diagnostic here.
1020   struct A {
1021     inline void *operator new(size_t) __attribute__((unused));
1022     inline void operator delete(void*) __attribute__((unused));
1023     A() {}
1024   };
1025 
1026   // FIXME: This is ill-formed, with a required diagnostic, for the same
1027   // reason.
1028   struct B {
1029     inline void operator delete(void*) __attribute__((unused));
1030     ~B() {}
1031   };
1032   struct C {
1033     inline void operator delete(void*) __attribute__((unused));
1034     virtual ~C() {}
1035     // expected-warning@-1 {{'operator delete' was marked unused but was used}}
1036   };
1037 
1038   struct D {
1039     inline void operator delete(void*) __attribute__((unused));
1040   };
1041   void h() { C::operator delete(0); }
1042   // expected-warning@-1 {{'operator delete' was marked unused but was used}}
1043 
1044 #pragma clang diagnostic pop
1045 } // namespace cwg261
1046 
1047 namespace cwg262 { // cwg262: 2.7
1048   int f(int = 0, ...);
1049   int k = f();
1050   int l = f(0);
1051   int m = f(0, 0);
1052 } // namespace cwg262
1053 
1054 namespace cwg263 { // cwg263: 3.3
1055   struct X {};
1056   struct Y {
1057 #if __cplusplus < 201103L
1058     friend X::X() throw();
1059     friend X::~X() throw();
1060 #elif __cplusplus <= 201703L
1061     friend constexpr X::X() noexcept;
1062     friend X::~X();
1063 #else
1064     friend constexpr X::X() noexcept;
1065     friend constexpr X::~X();
1066 #endif
1067     Y::Y();
1068     // expected-error@-1 {{extra qualification on member 'Y'}}
1069     Y::~Y();
1070     // expected-error@-1 {{extra qualification on member '~Y'}}
1071   };
1072 } // namespace cwg263
1073 
1074 // cwg265: dup 353
1075 // cwg266: na
1076 // cwg269: na
1077 // cwg270: na
1078 
1079 namespace cwg272 { // cwg272: 2.7
1080   struct X {
1081     void f() {
1082       this->~X();
1083       X::~X();
1084       ~X();
1085       // expected-error@-1 {{invalid argument type 'X' to unary expression}}
1086     }
1087   };
1088 } // namespace cwg272
1089 
1090 // cwg273 is in cwg273.cpp
1091 // cwg274: na
1092 
1093 namespace cwg275 { // cwg275: no
1094   namespace N {
1095     template <class T> void f(T) {} // #cwg275-N-f
1096     template <class T> void g(T) {} // #cwg275-N-g
1097     template <> void f(int);
1098     template <> void f(char);
1099     template <> void f(double);
1100     template <> void g(char);
1101   }
1102 
1103   using namespace N;
1104 
1105   namespace M {
1106     template <> void N::f(char) {}
1107     // expected-error@-1 {{cannot define or redeclare 'f' here because namespace 'M' does not enclose namespace 'N'}}
1108     template <class T> void g(T) {}
1109     template <> void g(char) {}
1110     // FIXME: this should be rejected in c++98 too
1111     template void f(long);
1112     // since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}}
1113     //   since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
1114     // FIXME: this should be rejected in c++98 too
1115     template void N::f(unsigned long);
1116     // since-cxx11-error@-1 {{explicit instantiation of 'f' not in a namespace enclosing 'N'}}
1117     //   since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
1118     template void h(long);
1119     // expected-error@-1 {{explicit instantiation of 'h' does not refer to a function template, variable template, member function, member class, or static data member}}
1120     template <> void f(double) {}
1121     // expected-error@-1 {{no function template matches function template specialization 'f'}}
1122   }
1123 
1124   template <class T> void g(T) {} // #cwg275-g
1125 
1126   template <> void N::f(char) {}
1127   template <> void f(int) {}
1128   // expected-error@-1 {{no function template matches function template specialization 'f'}}
1129 
1130   // FIXME: this should be rejected in c++98 too
1131   template void f(short);
1132   // since-cxx11-error@-1 {{explicit instantiation of 'cwg275::N::f' must occur in namespace 'N'}}
1133   //   since-cxx11-note@#cwg275-N-f {{explicit instantiation refers here}}
1134   template void N::f(unsigned short);
1135 
1136   // FIXME: this should probably be valid. the wording from the issue
1137   // doesn't clarify this, but it follows from the usual rules.
1138   template void g(int);
1139   // expected-error@-1 {{partial ordering for explicit instantiation of 'g' is ambiguous}}
1140   //   expected-note@#cwg275-g {{explicit instantiation candidate function 'cwg275::g<int>' template here [with T = int]}}
1141   //   expected-note@#cwg275-N-g {{explicit instantiation candidate function 'cwg275::N::g<int>' template here [with T = int]}}
1142 
1143   // FIXME: likewise, this should also be valid.
1144   template<typename T> void f(T) {} // #cwg275-f
1145   template void f(short);
1146   // expected-error@-1 {{partial ordering for explicit instantiation of 'f' is ambiguous}}
1147   //   expected-note@#cwg275-f {{explicit instantiation candidate function 'cwg275::f<short>' template here [with T = short]}}
1148   //   expected-note@#cwg275-N-f {{explicit instantiation candidate function 'cwg275::N::f<short>' template here [with T = short]}}
1149 } // namespace cwg275
1150 
1151 // cwg276: na
1152 
1153 namespace cwg277 { // cwg277: 3.1
1154   typedef int *intp;
1155   int *p = intp();
1156   static_assert(__enable_constant_folding(!intp()), "");
1157 } // namespace cwg277
1158 
1159 // cwg279 is in cwg279.cpp
1160 
1161 namespace cwg280 { // cwg280: 2.9
1162   typedef void f0();
1163   typedef void f1(int);
1164   typedef void f2(int, int);
1165   typedef void f3(int, int, int);
1166   struct A {
1167     operator f1*(); // #cwg280-A-f1
1168     operator f2*();
1169   };
1170   struct B {
1171     operator f0*(); // #cwg280-B-f0
1172   private:
1173     operator f3*(); // #cwg280-B-f3
1174   };
1175   struct C {
1176     operator f0*(); // #cwg280-C-f0
1177     operator f1*(); // #cwg280-C-f1
1178     operator f2*(); // #cwg280-C-f2
1179     operator f3*(); // #cwg280-C-f3
1180   };
1181   struct D : private A, B { // #cwg280-D
1182     operator f2*(); // #cwg280-D-f2
1183   } d;
1184   struct E : C, D {} e;
1185   void g() {
1186     d(); // ok, public
1187     d(0);
1188     // expected-error@-1 {{'operator void (*)(int)' is a private member of 'cwg280::A'}}
1189     //   expected-note@#cwg280-D {{constrained by private inheritance here}}
1190     //   expected-note@#cwg280-A-f1 {{member is declared here}}
1191     d(0, 0); // ok, suppressed by member in D
1192     d(0, 0, 0);
1193     // expected-error@-1 {{'operator void (*)(int, int, int)' is a private member of 'cwg280::B'}}
1194     //   expected-note@#cwg280-B-f3 {{declared private here}}
1195     e();
1196     // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1197     //   expected-note@#cwg280-B-f0 {{conversion candidate of type 'void (*)()'}}
1198     //   expected-note@#cwg280-C-f0 {{conversion candidate of type 'void (*)()'}}
1199     e(0);
1200     // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1201     //   expected-note@#cwg280-A-f1 {{conversion candidate of type 'void (*)(int)'}}
1202     //   expected-note@#cwg280-C-f1 {{conversion candidate of type 'void (*)(int)'}}
1203     e(0, 0);
1204     // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1205     //   expected-note@#cwg280-C-f2 {{conversion candidate of type 'void (*)(int, int)'}}
1206     //   expected-note@#cwg280-D-f2 {{conversion candidate of type 'void (*)(int, int)'}}
1207     e(0, 0, 0);
1208     // expected-error@-1 {{call to object of type 'struct E' is ambiguous}}
1209     //   expected-note@#cwg280-B-f3 {{conversion candidate of type 'void (*)(int, int, int)'}}
1210     //   expected-note@#cwg280-C-f3 {{conversion candidate of type 'void (*)(int, int, int)'}}
1211   }
1212 } // namespace cwg280
1213 
1214 namespace cwg281 { // cwg281: no
1215   void a();
1216   inline void b();
1217 
1218   void d();
1219   inline void e();
1220 
1221   struct S {
1222     friend inline void a(); // FIXME: ill-formed
1223     friend inline void b();
1224     friend inline void c(); // FIXME: ill-formed
1225     friend inline void d() {}
1226     friend inline void e() {}
1227     friend inline void f() {}
1228   };
1229 } // namespace cwg281
1230 
1231 namespace cwg283 { // cwg283: 2.7
1232   template<typename T> // #cwg283-template
1233   struct S {
1234     friend class T;
1235     // expected-error@-1 {{declaration of 'T' shadows template parameter}}
1236     //   expected-note@#cwg283-template {{template parameter is declared here}}
1237     class T;
1238     // expected-error@-1 {{declaration of 'T' shadows template parameter}}
1239     //   expected-note@#cwg283-template {{template parameter is declared here}}
1240   };
1241 } // namespace cwg283
1242 
1243 namespace cwg284 { // cwg284: no
1244   namespace A {
1245     struct X;
1246     enum Y {};
1247     class Z {};
1248   }
1249   namespace B {
1250     struct W;
1251     using A::X;
1252     using A::Y;
1253     using A::Z;
1254   }
1255   struct B::V {};
1256   // expected-error@-1 {{no struct named 'V' in namespace 'cwg284::B'}}
1257   struct B::W {};
1258   struct B::X {}; // FIXME: ill-formed
1259   enum B::Y e; // ok per cwg417
1260   class B::Z z; // ok per cwg417
1261 
1262   struct C {
1263     struct X;
1264     enum Y {};
1265     class Z {};
1266   };
1267   struct D : C {
1268     struct W;
1269     using C::X;
1270     using C::Y;
1271     using C::Z;
1272   };
1273   struct D::V {};
1274   // expected-error@-1 {{no struct named 'V' in 'cwg284::D'}}
1275   struct D::W {};
1276   struct D::X {}; // FIXME: ill-formed
1277   enum D::Y e2; // ok per cwg417
1278   class D::Z z2; // ok per cwg417
1279 } // namespace cwg284
1280 
1281 namespace cwg285 { // cwg285: 2.7
1282   template<typename T> void f(T, int); // #cwg285-f-T-int
1283   template<typename T> void f(int, T); // #cwg285-f-int-T
1284   template<> void f<int>(int, int) {}
1285   // expected-error@-1 {{function template specialization 'f' ambiguously refers to more than one function template; explicitly specify additional template arguments to identify a particular function template}}
1286   //   expected-note@#cwg285-f-int-T {{function template 'cwg285::f<int>' matches specialization [with T = int]}}
1287   //   expected-note@#cwg285-f-T-int {{function template 'cwg285::f<int>' matches specialization [with T = int]}}
1288 } // namespace cwg285
1289 
1290 namespace cwg286 { // cwg286: 2.8
1291   template<class T> struct A {
1292     class C {
1293       template<class T2> struct B {}; // #cwg286-B
1294     };
1295   };
1296 
1297   template<class T>
1298   template<class T2>
1299   struct A<T>::C::B<T2*> { };
1300 
1301   A<short>::C::B<int*> absip;
1302   // expected-error@-1 {{'B' is a private member of 'cwg286::A<short>::C'}}
1303   //   expected-note@#cwg286-B {{implicitly declared private here}}
1304 } // namespace cwg286
1305 
1306 // cwg288: na
1307 
1308 namespace cwg289 { // cwg289: 2.7
1309   struct A; // #cwg289-A
1310   struct B : A {};
1311   // expected-error@-1 {{base class has incomplete type}}
1312   //   expected-note@#cwg289-A {{forward declaration of 'cwg289::A'}}
1313 
1314   template<typename T> struct C { typename T::error error; };
1315   // expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}
1316   //   expected-note@#cwg289-C-int {{in instantiation of template class 'cwg289::C<int>' requested here}}
1317   struct D : C<int> {}; // #cwg289-C-int
1318 } // namespace cwg289
1319 
1320 // cwg290: na
1321 // cwg291: dup 391
1322 // cwg292 is in cwg292.cpp
1323 
1324 namespace cwg294 { // cwg294: no
1325   void f() throw(int);
1326   // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1327   //   since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1328   int main() {
1329     (void)static_cast<void (*)() throw()>(f); // FIXME: ill-formed in C++14 and before
1330     // FIXME: since-cxx17-error@-1 {{static_cast from 'void (*)() throw(int)' to 'void (*)() throw()' is not allowed}}
1331     //
1332     // Irony: the above is valid in C++17 and beyond, but that's exactly when
1333     // we reject it. In C++14 and before, this is ill-formed because an
1334     // exception-specification is not permitted in a type-id. In C++17, this is
1335     // valid because it's the inverse of a standard conversion sequence
1336     // containing a function pointer conversion. (Well, it's actually not valid
1337     // yet, as a static_cast is not permitted to reverse a function pointer
1338     // conversion, but that is being changed by core issue).
1339     (void)static_cast<void (*)() throw(int)>(f); // FIXME: ill-formed in C++14 and before
1340     // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1341     //   since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1342 
1343     void (*p)() throw() = f;
1344     // cxx98-14-error@-1 {{target exception specification is not superset of source}}
1345     // since-cxx17-error@-2 {{cannot initialize a variable of type 'void (*)() throw()' with an lvalue of type 'void () throw(int)': different exception specifications}}
1346     void (*q)() throw(int) = f;
1347     // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1348     //   since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1349   }
1350 } // namespace cwg294
1351 
1352 namespace cwg295 { // cwg295: 3.7
1353   typedef int f();
1354   const f g;
1355   // expected-warning@-1 {{'const' qualifier on function type 'f' (aka 'int ()') has no effect}}
1356   f &r = g;
1357   template<typename T> struct X {
1358     const T &f;
1359   };
1360   X<f> x = {g};
1361 
1362   typedef int U();
1363   typedef const U U;
1364   // expected-warning@-1 {{'const' qualifier on function type 'U' (aka 'int ()') has no effect}}
1365 
1366   typedef int (*V)();
1367   typedef volatile U *V;
1368   // expected-warning@-1 {{'volatile' qualifier on function type 'U' (aka 'int ()') has no effect}}
1369 } // namespace cwg295
1370 
1371 namespace cwg296 { // cwg296: 2.7
1372   struct A {
1373     static operator int() { return 0; }
1374     // expected-error@-1 {{conversion function must be a non-static member function}}
1375   };
1376 } // namespace cwg296
1377 
1378 namespace cwg298 { // cwg298: 3.1
1379   struct A {
1380     typedef int type;
1381     A();
1382     ~A();
1383   };
1384   typedef A B; // #cwg298-B
1385   typedef const A C; // #cwg298-C
1386 
1387   A::type i1;
1388   B::type i2;
1389   C::type i3;
1390 
1391   struct A a;
1392   struct B b;
1393   // expected-error@-1 {{typedef 'B' cannot be referenced with the 'struct' specifier}}
1394   //   expected-note@#cwg298-B {{declared here}}
1395   struct C c;
1396   // expected-error@-1 {{typedef 'C' cannot be referenced with the 'struct' specifier}}
1397   //   expected-note@#cwg298-C {{declared here}}
1398 
1399   B::B() {}
1400   // expected-error@-1 {{a type specifier is required for all declarations}}
1401   B::A() {} // ok
1402   C::~C() {}
1403   // expected-error@-1 {{destructor cannot be declared using a typedef 'C' (aka 'const cwg298::A') of the class name}}
1404 
1405   typedef struct D E; // #cwg298-E
1406   struct E {};
1407   // expected-error@-1 {{definition of type 'E' conflicts with typedef of the same name}}
1408   //   expected-note@#cwg298-E {{'E' declared here}}
1409 
1410   struct F {
1411     ~F();
1412   };
1413   typedef const F G;
1414   G::~F() {} // ok
1415 } // namespace cwg298
1416 
1417 namespace cwg299 { // cwg299: 2.8 c++11
1418   struct S {
1419     operator int();
1420   };
1421   struct T {
1422     operator int(); // #cwg299-int
1423     operator unsigned short(); // #cwg299-ushort
1424   };
1425   // FIXME: should this apply to c++98 mode?
1426   int *p = new int[S()];
1427   // cxx98-error@-1 {{implicit conversion from array size expression of type 'S' to integral type 'int' is a C++11 extension}}
1428   int *q = new int[T()]; // #cwg299-q
1429   // cxx98-11-error@#cwg299-q {{ambiguous conversion of array size expression of type 'T' to an integral or enumeration type}}
1430   //  cxx98-11-note@#cwg299-int {{conversion to integral type 'int' declared here}}
1431   //  cxx98-11-note@#cwg299-ushort {{conversion to integral type 'unsigned short' declared here}}
1432   // since-cxx14-error-re@#cwg299-q {{{{conversion from 'T' to 'unsigned (long long|long|int)' is ambiguous}}}}
1433   //  since-cxx14-note@#cwg299-int {{candidate function}}
1434   //  since-cxx14-note@#cwg299-ushort {{candidate function}}
1435 } // namespace cwg299
1436