xref: /llvm-project/clang/test/CXX/drs/cwg0xx.cpp (revision e29c085812e259910a3d8b6c2d2f471d1c3eede4)
1 // RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98,cxx98-14 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify=expected,since-cxx11,cxx98-14,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
3 // RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx11,cxx98-14,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
4 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
5 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
6 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
7 // RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors -triple %itanium_abi_triple
8 
9 #if __cplusplus == 199711L
10 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
11 // cxx98-error@-1 {{variadic macros are a C99 feature}}
12 #endif
13 
14 namespace cwg1 { // cwg1: no
15   namespace X { extern "C" void cwg1_f(int a = 1); }
16   namespace Y { extern "C" void cwg1_f(int a = 1); }
17   using X::cwg1_f; using Y::cwg1_f;
18   void g() {
19     cwg1_f(0);
20     // FIXME: This should be rejected, due to the ambiguous default argument.
21     cwg1_f();
22   }
23   namespace X {
24     using Y::cwg1_f;
25     void h() {
26       cwg1_f(0);
27       // FIXME: This should be rejected, due to the ambiguous default argument.
28       cwg1_f();
29     }
30   }
31 
32   namespace X {
33     void z(int);
34   }
35   void X::z(int = 1) {} // #cwg1-z
36   namespace X {
37     void z(int = 1);
38     // expected-error@-1 {{redefinition of default argument}}
39     //   expected-note@#cwg1-z {{previous definition is here}}
40   }
41 
42   void i(int = 1);
43   void j() {
44     void i(int = 1);
45     using cwg1::i;
46     i(0);
47     // FIXME: This should be rejected, due to the ambiguous default argument.
48     i();
49   }
50   void k() {
51     using cwg1::i;
52     void i(int = 1);
53     i(0);
54     // FIXME: This should be rejected, due to the ambiguous default argument.
55     i();
56   }
57 } // namespace cwg1
58 
59 namespace cwg3 { // cwg3: 2.7
60   template<typename T> struct A {};
61   template<typename T> void f(T) { A<T> a; } // #cwg3-f-T
62   template void f(int);
63   template<> struct A<int> {};
64   // expected-error@-1 {{explicit specialization of 'cwg3::A<int>' after instantiation}}
65   //   expected-note@#cwg3-f-T {{implicit instantiation first required here}}
66 } // namespace cwg3
67 
68 namespace cwg4 { // cwg4: 2.8
69   extern "C" {
70     static void cwg4_f(int) {}
71     static void cwg4_f(float) {}
72     void cwg4_g(int) {} // #cwg4-g-int
73     void cwg4_g(float) {}
74     // expected-error@-1 {{conflicting types for 'cwg4_g'}}
75     //   expected-note@#cwg4-g-int {{previous definition is here}}
76   }
77 } // namespace cwg4
78 
79 namespace cwg5 { // cwg5: 3.1
80   struct A {} a;
81   struct B {
82     B(const A&);
83     B(const B&);
84   };
85   const volatile B b = a;
86 
87   struct C { C(C&); };
88   struct D : C {};
89   struct E { operator D&(); } e;
90   const C c = e;
91 } // namespace cwg5
92 
93 namespace cwg7 { // cwg7: 3.4
94   class A { public: ~A(); };
95   class B : virtual private A {}; // #cwg7-B
96   class C : public B {} c; // #cwg7-C
97   // expected-error@#cwg7-C {{inherited virtual base class 'A' has private destructor}}
98   //   expected-note@#cwg7-C {{in implicit default constructor for 'cwg7::C' first required here}}
99   //   expected-note@#cwg7-B {{declared private here}}
100   // expected-error@#cwg7-C {{inherited virtual base class 'A' has private destructor}}
101   //   expected-note@#cwg7-C {{in implicit destructor for 'cwg7::C' first required here}}
102   //   expected-note@#cwg7-B {{declared private here}}
103   class VeryDerivedC : public B, virtual public A {} vdc;
104 
105   class X { ~X(); }; // #cwg7-X
106   class Y : X { ~Y() {} };
107   // expected-error@-1 {{base class 'X' has private destructor}}
108   //   expected-note@#cwg7-X {{implicitly declared private here}}
109 
110   namespace PR16370 { // This regressed the first time CWG7 was fixed.
111     struct S1 { virtual ~S1(); };
112     struct S2 : S1 {};
113     struct S3 : S2 {};
114     struct S4 : virtual S2 {};
115     struct S5 : S3, S4 {
116       S5();
117       ~S5();
118     };
119     S5::S5() {}
120   }
121 } // namespace cwg7
122 
123 namespace cwg8 { // cwg8: dup 45
124   class A {
125     struct U;
126     static const int k = 5;
127     void f();
128     template<typename, int, void (A::*)()> struct T;
129 
130     T<U, k, &A::f> *g();
131   };
132   A::T<A::U, A::k, &A::f> *A::g() { return 0; }
133 } // namespace cwg8
134 
135 namespace cwg9 { // cwg9: 2.8
136   struct B {
137   protected:
138     int m; // #cwg9-m
139     friend int R1();
140   };
141   struct N : protected B { // #cwg9-N
142     friend int R2();
143   } n;
144   int R1() { return n.m; }
145   // expected-error@-1 {{'m' is a protected member of 'cwg9::B'}}
146   //   expected-note@#cwg9-N {{constrained by protected inheritance here}}
147   //   expected-note@#cwg9-m {{member is declared here}}
148   int R2() { return n.m; }
149 } // namespace cwg9
150 
151 namespace cwg10 { // cwg10: dup 45
152   class A {
153     struct B {
154       A::B *p;
155     };
156   };
157 } // namespace cwg10
158 
159 namespace cwg11 { // cwg11: 2.7
160   template<typename T> struct A : T {
161     using typename T::U;
162     U u;
163   };
164   template<typename T> struct B : T {
165     using T::V;
166     V v;
167     // expected-error@-1 {{unknown type name 'V'}}
168   };
169   struct X { typedef int U; };
170   A<X> ax;
171 } // namespace cwg11
172 
173 namespace cwg12 { // cwg12: sup 239
174   enum E { e };
175   E &f(E, E = e);
176   void g() {
177     int &f(int, E = e);
178     // Under CWG12, these call two different functions.
179     // Under CWG239, they call the same function.
180     int &b = f(e);
181     int &c = f(1);
182   }
183 } // namespace cwg12
184 
185 namespace cwg13 { // cwg13: no
186   extern "C" void f(int);
187   void g(char);
188 
189   template<typename T> struct A {
190     A(void (*fp)(T));
191   };
192   template<typename T> int h(void (T));
193 
194   A<int> a1(f); // FIXME: We should reject this.
195   A<char> a2(g);
196   int a3 = h(f); // FIXME: We should reject this.
197   int a4 = h(g);
198 } // namespace cwg13
199 
200 namespace cwg14 { // cwg14: 3.4
201   namespace X { extern "C" int cwg14_f(); }
202   namespace Y { extern "C" int cwg14_f(); }
203   using namespace X;
204   using namespace Y;
205   int k = cwg14_f();
206 
207   class C {
208     int k;
209     friend int Y::cwg14_f();
210   } c;
211   namespace Z {
212     extern "C" int cwg14_f() { return c.k; }
213   }
214 
215   namespace X { typedef int T; typedef int U; } // #cwg14-X-U
216   namespace Y { typedef int T; typedef long U; } // #cwg14-Y-U
217   T t; // ok, same type both times
218   U u;
219   // expected-error@-1 {{reference to 'U' is ambiguous}}
220   //   expected-note@#cwg14-X-U {{candidate found by name lookup is 'cwg14::X::U'}}
221   //   expected-note@#cwg14-Y-U {{candidate found by name lookup is 'cwg14::Y::U'}}
222 } // namespace cwg14
223 
224 namespace cwg15 { // cwg15: 2.7
225   template<typename T> void f(int); // #cwg15-f-decl-first
226   template<typename T> void f(int = 0);
227   // expected-error@-1 {{default arguments cannot be added to a function template that has already been declared}}
228   //   expected-note@#cwg15-f-decl-first {{previous template declaration is here}}
229 } // namespace cwg15
230 
231 namespace cwg16 { // cwg16: 2.8
232   class A { // #cwg16-A
233     void f(); // #cwg16-A-f-decl
234     friend class C;
235   };
236   class B : A {}; // #cwg16-B
237   class C : B {
238     void g() {
239       f();
240       // expected-error@-1 {{'f' is a private member of 'cwg16::A'}}
241       //   expected-note@#cwg16-B {{constrained by implicitly private inheritance here}}
242       //   expected-note@#cwg16-A-f-decl {{member is declared here}}
243       A::f(); // #cwg16-A-f-call
244       // expected-error@#cwg16-A-f-call {{'A' is a private member of 'cwg16::A'}}
245       //   expected-note@#cwg16-B {{constrained by implicitly private inheritance here}}
246       //   expected-note@#cwg16-A {{member is declared here}}
247       // expected-error@#cwg16-A-f-call {{cannot cast 'cwg16::C' to its private base class 'cwg16::A'}}
248       //   expected-note@#cwg16-B {{implicitly declared private here}}
249     }
250   };
251 } // namespace cwg16
252 
253 namespace cwg17 { // cwg17: 2.7
254   class A {
255     int n;
256     int f();
257     struct C;
258   };
259   struct B : A {} b;
260   int A::f() { return b.n; }
261   struct A::C : A {
262     int g() { return n; }
263   };
264 } // namespace cwg17
265 
266 // cwg18: sup 577
267 
268 namespace cwg19 { // cwg19: 3.1
269   struct A {
270     int n; // #cwg19-n
271   };
272   struct B : protected A { // #cwg19-B
273   };
274   struct C : B {} c;
275   struct D : B {
276     int get1() { return c.n; }
277     // expected-error@-1 {{'n' is a protected member of 'cwg19::A'}}
278     //   expected-note@#cwg19-B {{constrained by protected inheritance here}}
279     //   expected-note@#cwg19-n {{member is declared here}}
280     int get2() { return ((A&)c).n; } // ok, A is an accessible base of B from here
281   };
282 } // namespace cwg19
283 
284 namespace cwg20 { // cwg20: 2.8
285   class X {
286   public:
287     X();
288   private:
289     X(const X&); // #cwg20-X-ctor
290   };
291   X &f();
292   X x = f();
293   // expected-error@-1 {{calling a private constructor of class 'cwg20::X'}}
294   //   expected-note@#cwg20-X-ctor {{declared private here}}
295 } // namespace cwg20
296 
297 namespace cwg21 { // cwg21: 3.4
298   template<typename T> struct A;
299   struct X {
300     template<typename T = int> friend struct A;
301     // expected-error@-1 {{default template argument not permitted on a friend template}}
302     template<typename T = int> friend struct B;
303     // expected-error@-1 {{default template argument not permitted on a friend template}}
304   };
305 } // namespace cwg21
306 
307 namespace cwg22 { // cwg22: sup 481
308   template<typename cwg22_T = cwg22_T> struct X;
309   // expected-error@-1 {{unknown type name 'cwg22_T'}}
310   typedef int T;
311   template<typename T = T> struct Y;
312 } // namespace cwg22
313 
314 namespace cwg23 { // cwg23: 2.7
315   template<typename T> void f(T, T); // #cwg23-f-T-T
316   template<typename T> void f(T, int); // #cwg23-f-T-int
317   void g() { f(0, 0); }
318   // expected-error@-1 {{call to 'f' is ambiguous}}
319   //   expected-note@#cwg23-f-T-T {{candidate function [with T = int]}}
320   //   expected-note@#cwg23-f-T-int {{candidate function [with T = int]}}
321 } // namespace cwg23
322 
323 // cwg24: na
324 
325 namespace cwg25 { // cwg25: 4
326   struct A {
327     void f() throw(int);
328     // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
329     //   since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
330   };
331   void (A::*f)() throw (int);
332   // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
333   //   since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
334   void (A::*g)() throw () = f;
335   // cxx98-14-error@-1 {{target exception specification is not superset of source}}
336   // since-cxx17-error@-2 {{different exception specifications}}
337   void (A::*g2)() throw () = 0;
338   void (A::*h)() throw (int, char) = f;
339   // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
340   //   since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
341   void (A::*i)() throw () = &A::f;
342   // cxx98-14-error@-1 {{target exception specification is not superset of source}}
343   // since-cxx17-error@-2 {{different exception specifications}}
344   void (A::*i2)() throw () = 0;
345   void (A::*j)() throw (int, char) = &A::f;
346   // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
347   //   since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
348   void x() {
349     g2 = f;
350     // cxx98-14-error@-1 {{target exception specification is not superset of source}}
351     // since-cxx17-error@-2 {{different exception specifications}}
352     h = f;
353     i2 = &A::f;
354     // cxx98-14-error@-1 {{target exception specification is not superset of source}}
355     // since-cxx17-error@-2 {{different exception specifications}}
356     j = &A::f;
357   }
358 } // namespace cwg25
359 
360 namespace cwg26 { // cwg26: 2.7
361   struct A { A(A, const A & = A()); };
362   // expected-error@-1 {{copy constructor must pass its first argument by reference}}
363   struct B {
364     B();
365     // FIXME: In C++98, we diagnose this twice.
366     B(const B &, B = B());
367     // cxx98-14-error@-1 {{recursive evaluation of default argument}}
368     //   cxx98-14-note@-2 {{default argument used here}}
369     // cxx98-error@-3 {{recursive evaluation of default argument}}
370     //   cxx98-note@-4 {{default argument used here}}
371   };
372   struct C {
373     static C &f();
374     C(const C &, C = f());
375     // expected-error@-1 {{recursive evaluation of default argument}}
376     //   expected-note@-2 {{default argument used here}}
377   };
378 } // namespace cwg26
379 
380 namespace cwg27 { // cwg27: 2.7
381   enum E { e } n;
382   E &m = true ? n : n;
383 } // namespace cwg27
384 
385 // cwg28: na lib
386 
387 namespace cwg29 { // cwg29: 3.4
388   void cwg29_f0(); // #cwg29-f0
389   void g0() { void cwg29_f0(); }
390   extern "C++" void g0_cxx() { void cwg29_f0(); }
391   extern "C" void g0_c() { void cwg29_f0(); }
392   // expected-error@-1 {{declaration of 'cwg29_f0' has a different language linkage}}
393   //   expected-note@#cwg29-f0 {{previous declaration is here}}
394 
395   extern "C" void cwg29_f1(); // #cwg29-f1
396   void g1() { void cwg29_f1(); }
397   extern "C" void g1_c() { void cwg29_f1(); }
398   extern "C++" void g1_cxx() { void cwg29_f1(); }
399   // expected-error@-1 {{declaration of 'cwg29_f1' has a different language linkage}}
400   //   expected-note@#cwg29-f1 {{previous declaration is here}}
401 
402   void g2() { void cwg29_f2(); } // #cwg29-f2
403   extern "C" void cwg29_f2();
404   // expected-error@-1 {{declaration of 'cwg29_f2' has a different language linkage}}
405   //   expected-note@#cwg29-f2 {{previous declaration is here}}
406 
407   extern "C" void g3() { void cwg29_f3(); } // #cwg29-f3
408   extern "C++" void cwg29_f3();
409   // expected-error@-1 {{declaration of 'cwg29_f3' has a different language linkage}}
410   //   expected-note@#cwg29-f3 {{previous declaration is here}}
411 
412   extern "C++" void g4() { void cwg29_f4(); } // #cwg29-f4
413   extern "C" void cwg29_f4();
414   // expected-error@-1 {{declaration of 'cwg29_f4' has a different language linkage}}
415   //   expected-note@#cwg29-f4 {{previous declaration is here}}
416 
417   extern "C" void g5();
418   extern "C++" void cwg29_f5();
419   void g5() {
420     void cwg29_f5(); // ok, g5 is extern "C" but we're not inside the linkage-specification here.
421   }
422 
423   extern "C++" void g6();
424   extern "C" void cwg29_f6();
425   void g6() {
426     void cwg29_f6(); // ok, g6 is extern "C" but we're not inside the linkage-specification here.
427   }
428 
429   extern "C" void g7();
430   extern "C++" void cwg29_f7(); // #cwg29-f7
431   extern "C" void g7() {
432     void cwg29_f7();
433     // expected-error@-1 {{declaration of 'cwg29_f7' has a different language linkage}}
434     //   expected-note@#cwg29-f7 {{previous declaration is here}}
435   }
436 
437   extern "C++" void g8();
438   extern "C" void cwg29_f8(); // #cwg29-f8
439   extern "C++" void g8() {
440     void cwg29_f8();
441     // expected-error@-1 {{declaration of 'cwg29_f8' has a different language linkage}}
442     //   expected-note@#cwg29-f8 {{previous declaration is here}}
443   }
444 } // namespace cwg29
445 
446 namespace cwg30 { // cwg30: sup 468 c++11
447   struct A {
448     template<int> static int f();
449   } a, *p = &a;
450   // FIXME: It's not clear whether CWG468 applies to C++98 too.
451   int x = A::template f<0>();
452   // cxx98-error@-1 {{'template' keyword outside of a template}}
453   int y = a.template f<0>();
454   // cxx98-error@-1 {{'template' keyword outside of a template}}
455   int z = p->template f<0>();
456   // cxx98-error@-1 {{'template' keyword outside of a template}}
457 } // namespace cwg30
458 
459 namespace cwg31 { // cwg31: 2.8
460   class X {
461   private:
462     void operator delete(void*); // #cwg31-delete
463   };
464   // We would call X::operator delete if X() threw (even though it can't,
465   // and even though we allocated the X using ::operator delete).
466   X *p = new X;
467   // expected-error@-1 {{'operator delete' is a private member of 'cwg31::X'}}
468   //   expected-note@#cwg31-delete {{declared private here}}
469 } // namespace cwg31
470 
471 // cwg32: na
472 
473 namespace cwg33 { // cwg33: 9
474   namespace X { struct S; void f(void (*)(S)); } // #cwg33-f-S
475   namespace Y { struct T; void f(void (*)(T)); } // #cwg33-f-T
476   void g(X::S);
477   template<typename Z> Z g(Y::T);
478   void h() { f(&g); }
479   // expected-error@-1 {{call to 'f' is ambiguous}}
480   //   expected-note@#cwg33-f-S {{candidate function}}
481   //   expected-note@#cwg33-f-T {{candidate function}}
482 
483   template<typename T> void t(X::S);
484   template<typename T, typename U = void> void u(X::S);
485   // expected-error@-1 0-1 {{default template arguments for a function template are a C++11 extension}}
486   void templ() { f(t<int>); f(u<int>); }
487 
488   // Even though v<int> cannot select the first overload, ADL considers it
489   // and adds namespace Z to the set of associated namespaces, and then picks
490   // Z::f even though that function has nothing to do with any associated type.
491   namespace Z { struct Q; void f(void(*)()); }
492   template<int> Z::Q v();
493   template<typename> void v();
494   void unrelated_templ() { f(v<int>); }
495 
496   namespace dependent {
497     struct X {};
498     template<class T> struct Y {
499       friend int operator+(X, void(*)(Y)) {}
500     };
501 
502     template<typename T> void f(Y<T>);
503     int use = X() + f<int>;
504     // expected-error@-1 {{invalid operands to binary expression ('X' and 'void (Y<int>)')}}
505   }
506 
507   namespace member {
508     struct Q {};
509     struct Y { friend int operator+(Q, Y (*)()); };
510     struct X { template<typename> static Y f(); };
511     int m = Q() + X().f<int>; // ok
512     int n = Q() + (&(X().f<int>)); // ok
513   }
514 } // namespace cwg33
515 
516 // cwg34: na
517 // cwg35: dup 178
518 
519 namespace cwg36 { // cwg36: 2.8
520 namespace example1 {
521   namespace A {
522     int i;
523   }
524 
525   namespace A1 {
526     using A::i;
527     using A::i;
528   }
529 
530   void f()
531   {
532     using A::i;
533     using A::i;
534   }
535 }
536 
537 namespace example2 {
538   struct A
539   {
540     int i;
541     static int j;
542   };
543 
544   struct B : A { };
545   struct C : A { };
546 
547   struct D : virtual B, virtual C
548   {
549     using B::i; // #cwg36-ex2-B-i-first
550     using B::i;
551     // expected-error@-1 {{redeclaration of using declaration}}
552     //   expected-note@#cwg36-ex2-B-i-first {{previous using declaration}}
553 
554     using C::i; // #cwg36-ex2-C-i-first
555     using C::i;
556     // expected-error@-1 {{redeclaration of using declaration}}
557     //   expected-note@#cwg36-ex2-C-i-first {{previous using declaration}}
558 
559     using B::j; // #cwg36-ex2-B-j-first
560     using B::j;
561     // expected-error@-1 {{redeclaration of using declaration}}
562     //   expected-note@#cwg36-ex2-B-j-first {{previous using declaration}}
563 
564     using C::j; // #cwg36-ex2-C-j-first
565     using C::j;
566     // expected-error@-1 {{redeclaration of using declaration}}
567     //   expected-note@#cwg36-ex2-C-j-first {{previous using declaration}}
568   };
569 }
570 
571 namespace example3 {
572   template<typename T>
573   struct A
574   {
575     T i;
576     static T j;
577   };
578 
579   template<typename T>
580   struct B : A<T> { };
581   template<typename T>
582   struct C : A<T> { };
583 
584   template<typename T>
585   struct D : virtual B<T>, virtual C<T>
586   {
587     using B<T>::i; // #cwg36-ex3-B-i-first
588     using B<T>::i;
589     // expected-error@-1 {{redeclaration of using declaration}}
590     //   expected-note@#cwg36-ex3-B-i-first {{previous using declaration}}
591 
592     using C<T>::i; // #cwg36-ex3-C-i-first
593     using C<T>::i;
594     // expected-error@-1 {{redeclaration of using declaration}}
595     //   expected-note@#cwg36-ex3-C-i-first {{previous using declaration}}
596 
597     using B<T>::j; // #cwg36-ex3-B-j-first
598     using B<T>::j;
599     // expected-error@-1 {{redeclaration of using declaration}}
600     //   expected-note@#cwg36-ex3-B-j-first {{previous using declaration}}
601 
602     using C<T>::j; // #cwg36-ex3-C-j-first
603     using C<T>::j;
604     // expected-error@-1 {{redeclaration of using declaration}}
605     //   expected-note@#cwg36-ex3-C-j-first {{previous using declaration}}
606   };
607 }
608 namespace example4 {
609   template<typename T>
610   struct E {
611     T k;
612   };
613 
614   template<typename T>
615   struct G : E<T> {
616     using E<T>::k; // #cwg36-E-k-first
617     using E<T>::k;
618     // expected-error@-1 {{redeclaration of using declaration}}
619     //   expected-note@#cwg36-E-k-first {{previous using declaration}}
620   };
621 }
622 } // namespace cwg36
623 
624 // cwg37: sup 475
625 
626 namespace cwg38 { // cwg38: 2.7
627   template<typename T> struct X {};
628   template<typename T> X<T> operator+(X<T> a, X<T> b) { return a; }
629   template X<int> operator+<int>(X<int>, X<int>);
630 } // namespace cwg38
631 
632 namespace cwg39 { // cwg39: no
633   namespace example1 {
634     struct A { int &f(int); };
635     struct B : A {
636       using A::f;
637       float &f(float);
638     } b;
639     int &r = b.f(0);
640   }
641 
642   namespace example2 {
643     struct A {
644       int &x(int); // #cwg39-A-x-decl
645       static int &y(int); // #cwg39-A-y-decl
646     };
647     struct V {
648       int &z(int);
649     };
650     struct B : A, virtual V {
651       using A::x; // #cwg39-using-A-x
652       float &x(float);
653       using A::y; // #cwg39-using-A-y
654       static float &y(float);
655       using V::z;
656       float &z(float);
657     };
658     struct C : A, B, virtual V {} c;
659     /* expected-warning@-1
660     {{direct base 'A' is inaccessible due to ambiguity:
661     struct cwg39::example2::C -> A
662     struct cwg39::example2::C -> B -> A}} */
663     int &x = c.x(0);
664     // expected-error@-1 {{member 'x' found in multiple base classes of different types}}
665     //   expected-note@#cwg39-A-x-decl {{member found by ambiguous name lookup}}
666     //   expected-note@#cwg39-using-A-x {{member found by ambiguous name lookup}}
667 
668     // FIXME: This is valid, because we find the same static data member either way.
669     int &y = c.y(0);
670     // expected-error@-1 {{member 'y' found in multiple base classes of different types}}
671     //   expected-note@#cwg39-A-y-decl {{member found by ambiguous name lookup}}
672     //   expected-note@#cwg39-using-A-y {{member found by ambiguous name lookup}}
673     int &z = c.z(0);
674   }
675 
676   namespace example3 {
677     struct A { static int f(); };
678     struct B : virtual A { using A::f; };
679     struct C : virtual A { using A::f; };
680     struct D : B, C {} d;
681     int k = d.f();
682   }
683 
684   namespace example4 {
685     struct A { int n; }; // #cwg39-ex4-A-n
686     struct B : A {};
687     struct C : A {};
688     struct D : B, C { int f() { return n; } };
689     /* expected-error@-1
690     {{non-static member 'n' found in multiple base-class subobjects of type 'A':
691     struct cwg39::example4::D -> B -> A
692     struct cwg39::example4::D -> C -> A}} */
693     //   expected-note@#cwg39-ex4-A-n {{member found by ambiguous name lookup}}
694   }
695 
696   namespace PR5916 {
697     // FIXME: This is valid.
698     struct A { int n; }; // #cwg39-A-n
699     struct B : A {};
700     struct C : A {};
701     struct D : B, C {};
702     int k = sizeof(D::n); // #cwg39-sizeof
703     /* expected-error@#cwg39-sizeof
704     {{non-static member 'n' found in multiple base-class subobjects of type 'A':
705     struct cwg39::PR5916::D -> B -> A
706     struct cwg39::PR5916::D -> C -> A}} */
707     //   expected-note@#cwg39-A-n {{member found by ambiguous name lookup}}
708 
709     // expected-error@#cwg39-sizeof {{unknown type name}}
710 #if __cplusplus >= 201103L
711     decltype(D::n) n;
712     /* since-cxx11-error@-1
713     {{non-static member 'n' found in multiple base-class subobjects of type 'A':
714     struct cwg39::PR5916::D -> B -> A
715     struct cwg39::PR5916::D -> C -> A}} */
716     //   since-cxx11-note@#cwg39-A-n {{member found by ambiguous name lookup}}
717 #endif
718   }
719 } // namespace cwg39
720 
721 // cwg40: na
722 
723 namespace cwg41 { // cwg41: 2.7
724   struct S f(S);
725 } // namespace cwg41
726 
727 namespace cwg42 { // cwg42: 2.7
728   struct A { static const int k = 0; };
729   struct B : A { static const int k = A::k; };
730 } // namespace cwg42
731 
732 // cwg43: na
733 
734 namespace cwg44 { // cwg44: sup 727
735   struct A {
736     template<int> void f();
737     template<> void f<0>();
738   };
739 } // namespace cwg44
740 
741 namespace cwg45 { // cwg45: 2.7
742   class A {
743     class B {};
744     class C : B {};
745     C c;
746   };
747 } // namespace cwg45
748 
749 namespace cwg46 { // cwg46: 2.7
750   template<typename> struct A { template<typename> struct B {}; };
751   template template struct A<int>::B<int>;
752   // expected-error@-1 {{expected unqualified-id}}
753 } // namespace cwg46
754 
755 namespace cwg47 { // cwg47: sup 329
756   template<typename T> struct A {
757     friend void f() { T t; } // #cwg47-f
758     // expected-error@-1 {{redefinition of 'f'}}
759     //   expected-note@#cwg47-b {{in instantiation of template class 'cwg47::A<float>' requested here}}
760     //   expected-note@#cwg47-f {{previous definition is here}}
761   };
762   A<int> a;
763   A<float> b; // #cwg47-b
764 
765   void f();
766   void g() { f(); }
767 } // namespace cwg47
768 
769 namespace cwg48 { // cwg48: 2.7
770   namespace {
771     struct S {
772       static const int m = 0;
773       static const int n = 0;
774       static const int o = 0;
775     };
776   }
777   int a = S::m;
778   // FIXME: We should produce a 'has internal linkage but is not defined'
779   // diagnostic for 'S::n'.
780   const int &b = S::n;
781   const int S::o;
782   const int &c = S::o;
783 } // namespace cwg48
784 
785 namespace cwg49 { // cwg49: 2.8
786   template<int*> struct A {}; // #cwg49-A
787   int k;
788 #if __has_feature(cxx_constexpr)
789   constexpr
790 #endif
791   int *const p = &k; // #cwg49-p
792   A<&k> a;
793   A<p> b; // #cwg49-b
794   // cxx98-error@#cwg49-b {{non-type template argument referring to object 'p' with internal linkage is a C++11 extension}}
795   //   cxx98-note@#cwg49-p {{non-type template argument refers to object here}}
796   // cxx98-14-error@#cwg49-b {{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}
797   //   cxx98-14-note@#cwg49-A {{template parameter is declared here}}
798   int *q = &k; // #cwg49-q
799   A<q> c; // #cwg49-c
800   // cxx98-error@#cwg49-c {{non-type template argument for template parameter of pointer type 'int *' must have its address taken}}
801   //   cxx98-note@#cwg49-A {{template parameter is declared here}}
802   // cxx11-14-error@#cwg49-c {{non-type template argument of type 'int *' is not a constant expression}}
803   //   cxx11-14-note@#cwg49-c {{read of non-constexpr variable 'q' is not allowed in a constant expression}}
804   //   cxx11-14-note@#cwg49-q {{declared here}}
805   //   cxx11-14-note@#cwg49-A {{template parameter is declared here}}
806   // since-cxx17-error@#cwg49-c {{non-type template argument is not a constant expression}}
807   //   since-cxx17-note@#cwg49-c {{read of non-constexpr variable 'q' is not allowed in a constant expression}}
808   //   since-cxx17-note@#cwg49-q {{declared here}}
809 } // namespace cwg49
810 
811 namespace cwg50 { // cwg50: 2.7
812   struct X; // #cwg50-X
813   extern X *p;
814   X *q = (X*)p;
815   X *r = static_cast<X*>(p);
816   X *s = const_cast<X*>(p);
817   X *t = reinterpret_cast<X*>(p);
818   X *u = dynamic_cast<X*>(p);
819   // expected-error@-1 {{'cwg50::X' is an incomplete type}}
820   //   expected-note@#cwg50-X {{forward declaration of 'cwg50::X'}}
821 } // namespace cwg50
822 
823 namespace cwg51 { // cwg51: 2.8
824   struct A {};
825   struct B : A {};
826   struct S {
827     operator A&();
828     operator B&();
829   } s;
830   A &a = s;
831 } // namespace cwg51
832 
833 namespace cwg52 { // cwg52: 2.8
834   struct A { int n; }; // #cwg52-A
835   struct B : private A {} b; // #cwg52-B
836   int k = b.A::n; // #cwg52-k
837   // FIXME: This first diagnostic is very strangely worded, and seems to be bogus.
838   // expected-error@#cwg52-k {{'A' is a private member of 'cwg52::A'}}
839   //   expected-note@#cwg52-B {{constrained by private inheritance here}}
840   //   expected-note@#cwg52-A {{member is declared here}}
841   // expected-error@#cwg52-k {{cannot cast 'struct B' to its private base class 'cwg52::A'}}
842   //   expected-note@#cwg52-B {{declared private here}}
843 } // namespace cwg52
844 
845 namespace cwg53 { // cwg53: 2.7
846   int n = 0;
847   enum E { e } x = static_cast<E>(n);
848 } // namespace cwg53
849 
850 namespace cwg54 { // cwg54: 2.8
851   struct A { int a; } a;
852   struct V { int v; } v;
853   struct B : private A, virtual V { int b; } b; // #cwg54-B
854 
855   A &sab = static_cast<A&>(b);
856   // expected-error@-1 {{cannot cast 'struct B' to its private base class 'A'}}
857   //   expected-note@#cwg54-B {{declared private here}}
858   A *spab = static_cast<A*>(&b);
859   // expected-error@-1 {{cannot cast 'struct B' to its private base class 'A'}}
860   //   expected-note@#cwg54-B {{declared private here}}
861   int A::*smab = static_cast<int A::*>(&B::b);
862   // expected-error@-1 {{cannot cast 'cwg54::B' to its private base class 'A'}}
863   //   expected-note@#cwg54-B {{declared private here}}
864   B &sba = static_cast<B&>(a);
865   // expected-error@-1 {{cannot cast private base class 'cwg54::A' to 'cwg54::B'}}
866   //   expected-note@#cwg54-B {{declared private here}}
867   B *spba = static_cast<B*>(&a);
868   // expected-error@-1 {{cannot cast private base class 'cwg54::A' to 'cwg54::B'}}
869   //   expected-note@#cwg54-B {{declared private here}}
870   int B::*smba = static_cast<int B::*>(&A::a);
871   // expected-error@-1 {{cannot cast private base class 'cwg54::A' to 'B'}}
872   //   expected-note@#cwg54-B {{declared private here}}
873 
874   V &svb = static_cast<V&>(b);
875   V *spvb = static_cast<V*>(&b);
876   int V::*smvb = static_cast<int V::*>(&B::b);
877   // expected-error@-1 {{conversion from pointer to member of class 'cwg54::B' to pointer to member of class 'V' via virtual base 'cwg54::V' is not allowed}}
878   B &sbv = static_cast<B&>(v);
879   // expected-error@-1 {{cannot cast 'struct V' to 'B &' via virtual base 'cwg54::V'}}
880   B *spbv = static_cast<B*>(&v);
881   // expected-error@-1 {{cannot cast 'cwg54::V *' to 'B *' via virtual base 'cwg54::V'}}
882   int B::*smbv = static_cast<int B::*>(&V::v);
883   // expected-error@-1 {{conversion from pointer to member of class 'cwg54::V' to pointer to member of class 'B' via virtual base 'cwg54::V' is not allowed}}
884 
885   A &cab = (A&)(b);
886   A *cpab = (A*)(&b);
887   int A::*cmab = (int A::*)(&B::b);
888   B &cba = (B&)(a);
889   B *cpba = (B*)(&a);
890   int B::*cmba = (int B::*)(&A::a);
891 
892   V &cvb = (V&)(b);
893   V *cpvb = (V*)(&b);
894   int V::*cmvb = (int V::*)(&B::b);
895   // expected-error@-1 {{conversion from pointer to member of class 'cwg54::B' to pointer to member of class 'V' via virtual base 'cwg54::V' is not allowed}}
896   B &cbv = (B&)(v);
897   // expected-error@-1 {{cannot cast 'struct V' to 'B &' via virtual base 'cwg54::V'}}
898   B *cpbv = (B*)(&v);
899   // expected-error@-1 {{cannot cast 'cwg54::V *' to 'B *' via virtual base 'cwg54::V'}}
900   int B::*cmbv = (int B::*)(&V::v);
901   // expected-error@-1 {{conversion from pointer to member of class 'cwg54::V' to pointer to member of class 'B' via virtual base 'cwg54::V' is not allowed}}
902 } // namespace cwg54
903 
904 namespace cwg55 { // cwg55: 2.7
905   enum E { e = 5 };
906   static_assert(e + 1 == 6, "");
907 } // namespace cwg55
908 
909 namespace cwg56 { // cwg56: 2.7
910   struct A {
911     typedef int T; // #cwg56-typedef-int-T-first
912     typedef int T;
913     // expected-error@-1 {{redefinition of 'T'}}
914     //   expected-note@#cwg56-typedef-int-T-first {{previous definition is here}}
915   };
916   struct B {
917     struct X;
918     typedef X X; // #cwg56-typedef-X-X-first
919     typedef X X;
920     // expected-error@-1 {{redefinition of 'X'}}
921     //   expected-note@#cwg56-typedef-X-X-first {{previous definition is here}}
922   };
923 } // namespace cwg56
924 
925 namespace cwg58 { // cwg58: 3.1
926   // FIXME: Ideally, we should have a CodeGen test for this.
927 #if __cplusplus >= 201103L
928   enum E1 { E1_0 = 0, E1_1 = 1 };
929   enum E2 { E2_0 = 0, E2_m1 = -1 };
930   struct X { E1 e1 : 1; E2 e2 : 1; };
931   static_assert(X{E1_1, E2_m1}.e1 == 1, "");
932   static_assert(X{E1_1, E2_m1}.e2 == -1, "");
933 #endif
934 } // namespace cwg58
935 
936 namespace cwg59 { // cwg59: 2.7
937 #pragma clang diagnostic push
938 #pragma clang diagnostic ignored "-Wdeprecated-volatile"
939   template<typename T> struct convert_to { operator T() const; };
940   struct A {}; // #cwg59-A
941   struct B : A {}; // #cwg59-B
942 
943   A a1 = convert_to<A>();
944   A a2 = convert_to<A&>();
945   A a3 = convert_to<const A>();
946   A a4 = convert_to<const volatile A>();
947   // cxx98-14-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::A'}}
948   //   cxx98-14-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::A') would lose volatile qualifier}}
949   //   cxx11-14-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::A') would lose const and volatile qualifiers}}
950   //   cxx98-14-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
951   A a5 = convert_to<const volatile A&>();
952   // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::A'}}
953   //   expected-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::A') would lose volatile qualifier}}
954   //   since-cxx11-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::A') would lose const and volatile qualifiers}}
955   //   expected-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
956 
957   B b1 = convert_to<B>();
958   B b2 = convert_to<B&>();
959   B b3 = convert_to<const B>();
960   B b4 = convert_to<const volatile B>();
961   // cxx98-14-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}
962   //   cxx98-14-note@#cwg59-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::B') would lose volatile qualifier}}
963   //   cxx11-14-note@#cwg59-B {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::B') would lose const and volatile qualifiers}}
964   //   cxx98-14-note@#cwg59-B {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
965   B b5 = convert_to<const volatile B&>();
966   // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}
967   //   expected-note@#cwg59-B {{candidate constructor (the implicit copy constructor) not viable: 1st argument ('const volatile cwg59::B') would lose volatile qualifier}}
968   //   since-cxx11-note@#cwg59-B {{candidate constructor (the implicit move constructor) not viable: 1st argument ('const volatile cwg59::B') would lose const and volatile qualifiers}}
969   //   expected-note@#cwg59-B {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
970 
971   A c1 = convert_to<B>();
972   A c2 = convert_to<B&>();
973   A c3 = convert_to<const B>();
974   A c4 = convert_to<const volatile B>();
975   // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}
976   //   expected-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'const A &' for 1st argument}}
977   //   since-cxx11-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'A &&' for 1st argument}}
978   //   expected-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
979   A c5 = convert_to<const volatile B&>();
980   // expected-error@-1 {{no viable constructor copying variable of type 'const volatile cwg59::B'}}
981   //   expected-note@#cwg59-A {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'const A &' for 1st argument}}
982   //   since-cxx11-note@#cwg59-A {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'const volatile cwg59::B' to 'A &&' for 1st argument}}
983   //   expected-note@#cwg59-A {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
984 
985   int n1 = convert_to<int>();
986   int n2 = convert_to<int&>();
987   int n3 = convert_to<const int>();
988   int n4 = convert_to<const volatile int>();
989   int n5 = convert_to<const volatile int&>();
990 #pragma clang diagnostic pop
991 } // namespace cwg59
992 
993 namespace cwg60 { // cwg60: 2.7
994   void f(int &);
995   int &f(...);
996   const int k = 0;
997   int &n = f(k);
998 } // namespace cwg60
999 
1000 namespace cwg61 { // cwg61: 3.4
1001   struct X {
1002     static void f();
1003   } x;
1004   struct Y {
1005     static void f();
1006     static void f(int);
1007   } y;
1008   // This is (presumably) valid, because x.f does not refer to an overloaded
1009   // function name.
1010   void (*p)() = &x.f;
1011   void (*q)() = &y.f;
1012   // expected-error@-1 {{cannot create a non-constant pointer to member function}}
1013   void (*r)() = y.f;
1014   // expected-error@-1 {{cannot create a non-constant pointer to member function}}
1015 } // namespace cwg61
1016 
1017 namespace cwg62 { // cwg62: 2.9
1018   struct A {
1019     struct { int n; } b;
1020   };
1021   template<typename T> struct X {};
1022   template<typename T> T get() { return get<T>(); }
1023   template<typename T> int take(T) { return 0; }
1024 
1025   X<A> x1;
1026   A a = get<A>();
1027 
1028   typedef struct { } *NoNameForLinkagePtr; // #cwg62-unnamed
1029   NoNameForLinkagePtr noNameForLinkagePtr;
1030 
1031   struct Danger {
1032     NoNameForLinkagePtr p;
1033   };
1034 
1035   X<NoNameForLinkagePtr> x2;
1036   // cxx98-error@-1 {{template argument uses unnamed type}}
1037   //   cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}
1038   X<const NoNameForLinkagePtr> x3;
1039   // cxx98-error@-1 {{template argument uses unnamed type}}
1040   //   cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}
1041   NoNameForLinkagePtr p1 = get<NoNameForLinkagePtr>();
1042   // cxx98-error@-1 {{template argument uses unnamed type}}
1043   //   cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}
1044   NoNameForLinkagePtr p2 = get<const NoNameForLinkagePtr>();
1045   // cxx98-error@-1 {{template argument uses unnamed type}}
1046   //   cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}
1047   int n1 = take(noNameForLinkagePtr);
1048   // cxx98-error@-1 {{template argument uses unnamed type}}
1049   //   cxx98-note@#cwg62-unnamed {{unnamed type used in template argument was declared here}}
1050 
1051   X<Danger> x4;
1052 
1053   void f() {
1054     struct NoLinkage {};
1055     X<NoLinkage> a;
1056     // cxx98-error@-1 {{template argument uses local type }}
1057     X<const NoLinkage> b;
1058     // cxx98-error@-1 {{template argument uses local type }}
1059     get<NoLinkage>();
1060     // cxx98-error@-1 {{template argument uses local type }}
1061     get<const NoLinkage>();
1062     // cxx98-error@-1 {{template argument uses local type }}
1063     X<void (*)(NoLinkage A::*)> c;
1064     // cxx98-error@-1 {{template argument uses local type }}
1065     X<int NoLinkage::*> d;
1066     // cxx98-error@-1 {{template argument uses local type }}
1067   }
1068 } // namespace cwg62
1069 
1070 namespace cwg63 { // cwg63: 2.7
1071   template<typename T> struct S { typename T::error e; };
1072   extern S<int> *p;
1073   void *q = p;
1074 } // namespace cwg63
1075 
1076 namespace cwg64 { // cwg64: 2.7
1077   template<class T> void f(T);
1078   template<class T> void f(T*);
1079   template<> void f(int*);
1080   template<> void f<int>(int*);
1081   template<> void f(int);
1082 } // namespace cwg64
1083 
1084 // cwg65: na
1085 
1086 namespace cwg66 { // cwg66: no
1087   namespace X {
1088     int f(int n); // #cwg66-f-first
1089   }
1090   using X::f;
1091   namespace X {
1092     int f(int n = 0);
1093     int f(int, int);
1094   }
1095   // FIXME: The first two calls here should be accepted.
1096   int a = f();
1097   // expected-error@-1 {{no matching function for call to 'f'}}
1098   //   expected-note@#cwg66-f-first {{candidate function not viable: requires single argument 'n', but no arguments were provided}}
1099   int b = f(1);
1100   int c = f(1, 2);
1101   // expected-error@-1 {{no matching function for call to 'f'}}
1102   //   expected-note@#cwg66-f-first {{candidate function not viable: requires single argument 'n', but 2 arguments were provided}}
1103 } // namespace cwg66
1104 
1105 // cwg67: na
1106 
1107 namespace cwg68 { // cwg68: 2.8
1108   template<typename T> struct X {};
1109   struct ::cwg68::X<int> x1;
1110   struct ::cwg68::template X<int> x2;
1111   // cxx98-error@-1 {{'template' keyword outside of a template}}
1112   struct Y {
1113     friend struct X<int>;
1114     friend struct ::cwg68::X<char>;
1115     friend struct ::cwg68::template X<double>;
1116     // cxx98-error@-1 {{'template' keyword outside of a template}}
1117   };
1118   template<typename>
1119   struct Z {
1120     friend struct ::cwg68::template X<double>;
1121     friend typename ::cwg68::X<double>;
1122     // cxx98-error@-1 {{unelaborated friend declaration is a C++11 extension; specify 'struct' to befriend 'typename ::cwg68::X<double>'}}
1123   };
1124 } // namespace cwg68
1125 
1126 namespace cwg69 { // cwg69: 9
1127   template<typename T> static void f() {} // #cwg69-f
1128   // FIXME: Should we warn here?
1129   inline void g() { f<int>(); }
1130   extern template void f<char>();
1131   // cxx98-error@-1 {{extern templates are a C++11 extension}}
1132   // expected-error@-2 {{explicit instantiation declaration of 'f' with internal linkage}}
1133   template<void(*)()> struct Q {};
1134   Q<&f<int> > q;
1135   // cxx98-error@-1 {{non-type template argument referring to function 'f<int>' with internal linkage is a C++11 extension}}
1136   //   cxx98-note@#cwg69-f {{non-type template argument refers to function here}}
1137 } // namespace cwg69
1138 
1139 namespace cwg70 { // cwg70: 2.7
1140   template<int> struct A {};
1141   template<int I, int J> int f(int (&)[I + J], A<I>, A<J>);
1142   int arr[7];
1143   int k = f(arr, A<3>(), A<4>());
1144 } // namespace cwg70
1145 
1146 // cwg71: na
1147 // cwg72: dup 69
1148 
1149 namespace cwg73 { // cwg73: sup 1652
1150 #if __cplusplus >= 201103L
1151   int a, b;
1152   static_assert(&a + 1 != &b, "");
1153   // since-cxx11-error@-1 {{static assertion expression is not an integral constant expression}}
1154   //   since-cxx11-note@-2 {{comparison against pointer '&a + 1' that points past the end of a complete object has unspecified value}}
1155 #endif
1156 } // namespace cwg73
1157 
1158 namespace cwg74 { // cwg74: 2.7
1159   enum E { k = 5 };
1160   int (*p)[k] = new int[k][k];
1161 } // namespace cwg74
1162 
1163 namespace cwg75 { // cwg75: 2.7
1164   struct S {
1165     static int n = 0;
1166     // expected-error@-1 {{non-const static data member must be initialized out of line}}
1167   };
1168 } // namespace cwg75
1169 
1170 namespace cwg76 { // cwg76: 2.7
1171   const volatile int n = 1;
1172   static_assert(n, "");
1173   // expected-error@-1 {{static assertion expression is not an integral constant expression}}
1174   //   expected-note@-2 {{read of volatile-qualified type 'const volatile int' is not allowed in a constant expression}}
1175 } // namespace cwg76
1176 
1177 namespace cwg77 { // cwg77: 2.7
1178   struct A {
1179     struct B {};
1180     friend struct B;
1181   };
1182 } // namespace cwg77
1183 
1184 namespace cwg78 { // cwg78: sup ????
1185   // Under CWG78, this is valid, because 'k' has static storage duration, so is
1186   // zero-initialized.
1187   const int k;
1188   // expected-error@-1 {{default initialization of an object of const type 'const int'}}
1189 } // namespace cwg78
1190 
1191 // cwg79: na
1192 
1193 namespace cwg80 { // cwg80: 2.9
1194   struct A {
1195     int A;
1196   };
1197   struct B {
1198     static int B;
1199     // expected-error@-1 {{member 'B' has the same name as its class}}
1200   };
1201   struct C {
1202     int C;
1203     // expected-error@-1 {{member 'C' has the same name as its class}}
1204     C();
1205   };
1206   struct D {
1207     D();
1208     int D;
1209     // expected-error@-1 {{member 'D' has the same name as its class}}
1210   };
1211 } // namespace cwg80
1212 
1213 // cwg81: na
1214 // cwg82: dup 48
1215 
1216 namespace cwg83 { // cwg83: 2.7
1217   int &f(const char*);
1218   char &f(char *);
1219   int &k = f("foo");
1220 } // namespace cwg83
1221 
1222 namespace cwg84 { // cwg84: 2.7
1223   struct B;
1224   struct A { operator B() const; };
1225   struct C {};
1226   struct B {
1227     B(B&); // #cwg84-copy-ctor
1228     B(C); // #cwg84-ctor-from-C
1229     operator C() const;
1230   };
1231   A a;
1232   // Cannot use B(C) / operator C() pair to construct the B from the B temporary
1233   // here. In C++17, we initialize the B object directly using 'A::operator B()'.
1234   B b = a;
1235   // cxx98-14-error@-1 {{no viable constructor copying variable of type 'B'}}
1236   //   cxx98-14-note@#cwg84-copy-ctor {{candidate constructor not viable: expects an lvalue for 1st argument}}
1237   //   cxx98-14-note@#cwg84-ctor-from-C {{candidate constructor not viable: no known conversion from 'B' to 'C' for 1st argument}}
1238 } // namespace cwg84
1239 
1240 namespace cwg85 { // cwg85: 3.4
1241   struct A {
1242     struct B;
1243     struct B {}; // #cwg85-B-def
1244     struct B;
1245     // expected-error@-1 {{class member cannot be redeclared}}
1246     //   expected-note@#cwg85-B-def {{previous declaration is here}}
1247 
1248     union U;
1249     union U {}; // #cwg85-U-def
1250     union U;
1251     // expected-error@-1 {{class member cannot be redeclared}}
1252     //   expected-note@#cwg85-U-def {{previous declaration is here}}
1253 
1254 #if __cplusplus >= 201103L
1255     enum E1 : int;
1256     enum E1 : int { e1 }; // #cwg85-E1-def
1257     enum E1 : int;
1258     // since-cxx11-error@-1 {{class member cannot be redeclared}}
1259     //   since-cxx11-note@#cwg85-E1-def {{previous declaration is here}}
1260 
1261     enum class E2;
1262     enum class E2 { e2 }; // #cwg85-E2-def
1263     enum class E2;
1264     // since-cxx11-error@-1 {{class member cannot be redeclared}}
1265     //   since-cxx11-note@#cwg85-E2-def {{previous declaration is here}}
1266 #endif
1267   };
1268 
1269   template <typename T>
1270   struct C {
1271     struct B {}; // #cwg85-C-B-def
1272     struct B;
1273     // expected-error@-1 {{class member cannot be redeclared}}
1274     //   expected-note@#cwg85-C-B-def {{previous declaration is here}}
1275   };
1276 } // namespace cwg85
1277 
1278 // cwg86: dup 446
1279 
1280 namespace cwg87 { // cwg87: no
1281   // FIXME: Superseded by cwg1975
1282   template<typename T> struct X {};
1283   // FIXME: This is invalid.
1284   X<void() throw()> x;
1285   // This is valid under cwg87 but not under cwg1975.
1286   X<void(void() throw())> y;
1287 } // namespace cwg87
1288 
1289 namespace cwg88 { // cwg88: 2.8
1290   template<typename T> struct S {
1291     static const int a = 1; // #cwg88-a
1292     static const int b;
1293   };
1294   template<> const int S<int>::a = 4;
1295   // expected-error@-1 {{static data member 'a' already has an initializer}}
1296   //   expected-note@#cwg88-a {{previous initialization is here}}
1297   template<> const int S<int>::b = 4;
1298 } // namespace cwg88
1299 
1300 // cwg89: na
1301 
1302 namespace cwg90 { // cwg90: 2.7
1303   struct A {
1304     template<typename T> friend void cwg90_f(T);
1305   };
1306   struct B : A {
1307     template<typename T> friend void cwg90_g(T);
1308     struct C {};
1309     union D {};
1310   };
1311   struct E : B {};
1312   struct F : B::C {};
1313 
1314   void test() {
1315     cwg90_f(A());
1316     cwg90_f(B());
1317     cwg90_f(B::C());
1318     // expected-error@-1 {{use of undeclared identifier 'cwg90_f'}}
1319     cwg90_f(B::D());
1320     // expected-error@-1 {{use of undeclared identifier 'cwg90_f'}}
1321     cwg90_f(E());
1322     cwg90_f(F());
1323     // expected-error@-1 {{use of undeclared identifier 'cwg90_f'}}
1324 
1325     cwg90_g(A());
1326     // expected-error@-1 {{use of undeclared identifier 'cwg90_g'}}
1327     cwg90_g(B());
1328     cwg90_g(B::C());
1329     cwg90_g(B::D());
1330     cwg90_g(E());
1331     cwg90_g(F());
1332     // expected-error@-1 {{use of undeclared identifier 'cwg90_g'}}
1333   }
1334 } // namespace cwg90
1335 
1336 namespace cwg91 { // cwg91: 2.7
1337   union U { friend int f(U); };
1338   int k = f(U());
1339 } // namespace cwg91
1340 
1341 namespace cwg92 { // cwg92: 4 c++17
1342   void f() throw(int, float);
1343   // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1344   //   since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1345   void (*p)() throw(int) = &f; // #cwg92-p
1346   // since-cxx17-error@#cwg92-p {{ISO C++17 does not allow dynamic exception specifications}}
1347   //   since-cxx17-note@#cwg92-p {{use 'noexcept(false)' instead}}
1348   // cxx98-14-error@#cwg92-p {{target exception specification is not superset of source}}
1349   // since-cxx17-warning@#cwg92-p {{target exception specification is not superset of source}}
1350   void (*q)() throw(int);
1351   // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1352   //   since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1353   void (**pp)() throw() = &q;
1354   // cxx98-14-error@-1 {{exception specifications are not allowed beyond a single level of indirection}}
1355   // since-cxx17-error@-2 {{cannot initialize a variable of type 'void (**)() throw()' with an rvalue of type 'void (**)() throw(int)'}}
1356 
1357   void g(void() throw()); // #cwg92-g
1358   // cxx98-14-warning@-1 {{mangled name of 'g' will change in C++17 due to non-throwing exception specification in function signature}}
1359   void h() throw() {
1360     g(f);
1361     // cxx98-14-error@-1 {{target exception specification is not superset of source}}
1362     // since-cxx17-error@-2 {{no matching function for call to 'g'}}
1363     //   since-cxx17-note@#cwg92-g {{candidate function not viable: no known conversion from 'void () throw(int, float)' to 'void (*)() throw()' for 1st argument}}
1364     g(q);
1365     // cxx98-14-error@-1 {{target exception specification is not superset of source}}
1366     // since-cxx17-error@-2 {{no matching function for call to 'g'}}
1367     //   since-cxx17-note@#cwg92-g {{candidate function not viable: no known conversion from 'void (*)() throw(int)' to 'void (*)() throw()' for 1st argument}}
1368   }
1369 
1370   // Prior to C++17, this is OK because the exception specification is not
1371   // considered in this context. In C++17, we *do* perform an implicit
1372   // conversion (which performs initialization), and the exception specification
1373   // is part of the type of the parameter, so this is invalid.
1374   template<void() throw()> struct X {}; // since-cxx17-note {{template parameter is declared here}}
1375   X<&f> xp;
1376   // since-cxx17-error@-1 {{value of type 'void (*)() throw(int, float)' is not implicitly convertible to 'void (*)() throw()'}}
1377 
1378   template<void() throw(int)> struct Y {};
1379   // since-cxx17-error@-1 {{ISO C++17 does not allow dynamic exception specifications}}
1380   //   since-cxx17-note@-2 {{use 'noexcept(false)' instead}}
1381   Y<&h> yp; // ok
1382 } // namespace cwg92
1383 
1384 // cwg93: na
1385 
1386 namespace cwg94 { // cwg94: 2.7
1387   struct A { static const int n = 5; };
1388   int arr[A::n];
1389 } // namespace cwg94
1390 
1391 namespace cwg95 { // cwg95: 3.3
1392   struct A;
1393   struct B;
1394   namespace N {
1395     class C {
1396       friend struct A;
1397       friend struct B;
1398       static void f(); // #cwg95-C-f
1399     };
1400     struct A *p; // cwg95::A, not cwg95::N::A.
1401   }
1402   A *q = N::p; // ok, same type
1403   struct B { void f() { N::C::f(); } };
1404   // expected-error@-1 {{'f' is a private member of 'cwg95::N::C'}}
1405   //   expected-note@#cwg95-C-f {{implicitly declared private here}}
1406 } // namespace cwg95
1407 
1408 namespace cwg96 { // cwg96: sup P1787
1409   struct A {
1410     void f(int);
1411     template<typename T> int f(T);
1412     template<typename T> struct S {};
1413   } a;
1414   template<template<typename> class X> struct B {};
1415 
1416   template<typename T>
1417   void test() {
1418     int k1 = a.template f<int>(0);
1419     // FIXME: This is ill-formed, because 'f' is not a template-id and does not
1420     // name a class template.
1421     // FIXME: What about alias templates?
1422     int k2 = a.template f(1);
1423     // expected-error@-1 {{a template argument list is expected after a name prefixed by the template keyword}}
1424     A::template S<int> s;
1425     B<A::template S> b;
1426   }
1427 } // namespace cwg96
1428 
1429 namespace cwg97 { // cwg97: 2.7
1430   struct A {
1431     static const int a = false;
1432     static const int b = !a;
1433   };
1434 } // namespace cwg97
1435 
1436 namespace cwg98 { // cwg98: 2.7
1437   void test(int n) {
1438     switch (n) {
1439       try { // #cwg98-try
1440         case 0:
1441         // expected-error@-1 {{cannot jump from switch statement to this case label}}
1442         //   expected-note@#cwg98-try {{jump bypasses initialization of try block}}
1443         x:
1444           throw n;
1445       } catch (...) { // #cwg98-catch
1446         case 1:
1447         // expected-error@-1 {{cannot jump from switch statement to this case label}}
1448         //   expected-note@#cwg98-catch {{jump bypasses initialization of catch block}}
1449         y:
1450           throw n;
1451       }
1452       case 2:
1453         goto x;
1454         // expected-error@-1 {{cannot jump from this goto statement to its label}}
1455         //   expected-note@#cwg98-try {{jump bypasses initialization of try block}}
1456       case 3:
1457         goto y;
1458         // expected-error@-1 {{cannot jump from this goto statement to its label}}
1459         //   expected-note@#cwg98-catch {{jump bypasses initialization of catch block}}
1460     }
1461   }
1462 } // namespace cwg98
1463 
1464 namespace cwg99 { // cwg99: sup 214
1465   template<typename T> void f(T&);
1466   template<typename T> int &f(const T&);
1467   const int n = 0;
1468   int &r = f(n);
1469 } // namespace cwg99
1470