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