[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / CXX / drs / cwg3xx.cpp
blob10c8d86ed16a0dbcf9ccd4ea9ced4b2f9db7a07e
1 // RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20-23,cxx23,since-cxx11,since-cxx17,since-cxx23 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++20 -verify=expected,cxx98-20,cxx20-23,since-cxx11,since-cxx17 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++17 -verify=expected,cxx98-17,cxx98-20,since-cxx11,since-cxx17 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++14 -verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx11-14,since-cxx11 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++11 -verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx11-14,since-cxx11 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++98 -verify=expected,cxx98-14,cxx98-17,cxx98-20,cxx98 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
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 #if __cplusplus == 199711L
14 #define __enable_constant_folding(x) (__builtin_constant_p(x) ? (x) : (x))
15 #else
16 #define __enable_constant_folding
17 #endif
19 namespace cwg300 { // cwg300: yes
20 template<typename R, typename A> void f(R (&)(A)) {}
21 int g(int);
22 void h() { f(g); }
25 namespace cwg301 { // cwg301: 3.5
26 // see also cwg38
27 struct S;
28 template<typename T> void operator+(T, T);
29 void operator-(S, S);
31 void f() {
32 bool a = (void(*)(S, S))operator+<S> < (void(*)(S, S))operator+<S>;
33 // expected-warning@-1 {{ordered comparison of function pointers ('void (*)(S, S)' and 'void (*)(S, S)')}}
34 bool b = (void(*)(S, S))operator- < (void(*)(S, S))operator-;
35 // cxx98-17-warning@-1 {{ordered comparison of function pointers ('void (*)(S, S)' and 'void (*)(S, S)')}}
36 // cxx20-23-error@-2 {{expected '>'}}
37 // cxx20-23-note@-3 {{to match this '<'}}
38 bool c = (void(*)(S, S))operator+ < (void(*)(S, S))operator-;
39 // expected-error@-1 {{expected '>'}}
40 // expected-note@-2 {{to match this '<'}}
43 template<typename T> void f() {
44 // FIXME: We are emitting a lot of bogus diagnostics here.
45 typename T::template operator+<int> a;
46 // expected-error@-1 {{typename specifier refers to a non-type template}}
47 // expected-error@-2 {{'template' keyword not permitted here}}
48 // expected-error@-3 {{a type specifier is required for all declarations}}
49 // expected-error@-4 {{'operator+' cannot be the name of a variable or data member}}
50 // expected-error@-5 {{expected ';' at end of declaration}}
51 // FIXME: This shouldn't say (null).
52 class T::template operator+<int> b;
53 // expected-error@-1 {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}}
54 enum T::template operator+<int> c;
55 // expected-error@-1 {{expected identifier}}
56 enum T::template operator+<int>::E d;
57 // expected-error@-1 {{qualified name refers into a specialization of function template 'T::template operator +'}}
58 // expected-error@-2 {{ISO C++ forbids forward references to 'enum' types}}
59 enum T::template X<int>::E e;
60 T::template operator+<int>::foobar();
61 // expected-error@-1 {{qualified name refers into a specialization of function template 'T::template operator +'}}
62 T::template operator+<int>(0); // ok
65 // FIXME: We are emitting a bunch of bogus diagnostics for the next 3 lines.
66 // All of them do a bad job at explaining that 'class' is not allowed here.
67 template<typename T> class operator&<T*> {};
68 // expected-error@-1 {{declaration of anonymous class must be a definition}}
69 // expected-error@-2 {{declaration does not declare anything}}
70 template<typename T> class T::operator& {};
71 // expected-error@-1 {{expected identifier}}
72 // expected-error@-2 {{declaration of anonymous class must be a definition}}
73 // expected-error@-3 {{declaration does not declare anything}}
74 template<typename T> class S::operator&<T*> {};
75 // expected-error@-1 {{expected identifier}}
76 // expected-error@-2 {{declaration of anonymous class must be a definition}}
77 // expected-error@-3 {{declaration does not declare anything}}
80 namespace cwg302 { // cwg302: 3.0
81 struct A { A(); ~A(); };
82 #if __cplusplus < 201103L
83 struct B {
84 // expected-error@-1 {{implicit default constructor for 'cwg302::B' must explicitly initialize the const member 'n'}}
85 // expected-note@#cwg302-b {{in implicit default constructor for 'cwg302::B' first required here}}
86 // expected-note@#cwg302-B-n {{declared here}}
87 const int n; // #cwg302-B-n
88 A a;
89 } b = B(); // #cwg302-b
90 // Trivial default constructor C::C() is not called here.
91 struct C {
92 const int n;
93 } c = C();
94 #else
95 struct B {
96 const int n; // #cwg302-B-n
97 A a;
98 } b = B();
99 // expected-error@-1 {{call to implicitly-deleted default constructor of 'B'}}
100 // expected-note@#cwg302-B-n {{default constructor of 'B' is implicitly deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
101 // C::C() is called here, because even though it's trivial, it's deleted.
102 struct C {
103 const int n; // #cwg302-C-n
104 } c = C();
105 // expected-error@-1 {{call to implicitly-deleted default constructor of 'C'}}
106 // expected-note@#cwg302-C-n {{default constructor of 'C' is implicitly deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
107 struct D {
108 const int n = 0;
109 } d = D();
110 #endif
113 // cwg303: na
115 namespace cwg304 { // cwg304: 2.9
116 typedef int &a;
117 int n = a();
118 // expected-error@-1 {{reference to type 'int' requires an initializer}}
120 struct S { int &b; }; // #cwg304-S
121 // cxx98-error@-1 {{reference to type 'int' requires an initializer}}
122 // cxx98-note@#cwg304-m {{in value-initialization of type 'S' here}}
123 int m = S().b; // #cwg304-m
124 // since-cxx11-error@-1 {{call to implicitly-deleted default constructor of 'S'}}
125 // since-cxx11-note@#cwg304-S {{default constructor of 'S' is implicitly deleted because field 'b' of reference type 'int &' would not be initialized}}
128 namespace cwg305 { // cwg305: no
129 struct A {
130 typedef A C;
132 void f(A *a) {
133 struct A {};
134 a->~A();
135 a->~C();
137 typedef A B;
138 void g(B *b) {
139 b->~B();
140 b->~C();
142 void h(B *b) {
143 struct B {}; // #cwg305-h-B
144 b->~B();
145 // expected-error@-1 {{destructor type 'B' in object destruction expression does not match the type 'B' (aka 'cwg305::A') of the object being destroyed}}
146 // expected-note@#cwg305-h-B {{type 'B' found by destructor name lookup}}
149 template<typename T> struct X {};
150 void i(X<int>* x) {
151 struct X {};
152 x->~X<int>();
153 x->~X();
154 x->~X<char>();
155 // expected-error@-1 {{no member named '~X' in 'cwg305::X<int>'}}
158 #if __cplusplus >= 201103L
159 struct Y {
160 template<typename T> using T1 = Y;
162 template<typename T> using T2 = Y;
163 void j(Y *y) {
164 y->~T1<int>();
165 y->~T2<int>();
167 struct Z {
168 template<typename T> using T2 = T;
170 void k(Z *z) {
171 z->~T1<int>();
172 // expected-error@-1 {{no member named 'T1' in 'cwg305::Z'}}
173 z->~T2<int>();
174 // expected-error@-1 {{no member named '~int' in 'cwg305::Z'}}
175 z->~T2<Z>();
178 // FIXME: This is valid.
179 namespace Q {
180 template<typename A> struct R {};
182 template<typename A> using R = Q::R<int>;
183 void qr(Q::R<int> x) { x.~R<char>(); }
184 // expected-error@-1 {{no member named '~R' in 'cwg305::Q::R<int>'}}
185 #endif
188 namespace cwg306 { // cwg306: dup 39
189 struct A { struct B {}; };
190 struct C { typedef A::B B; };
191 struct D : A, A::B, C {};
192 D::B b;
194 struct X {}; // #cwg306-X
195 template<typename T> struct Y { typedef T X; }; // #cwg306-typedef-X
196 template<typename T> struct Z : X, Y<T> {};
197 Z<X>::X zx;
198 Z<const X>::X zcx;
199 // expected-error@-1 {{member 'X' found in multiple base classes of different types}}
200 // expected-note@#cwg306-X {{member type 'cwg306::X' found}}
201 // expected-note@#cwg306-typedef-X {{member type 'const cwg306::X' found}}
204 // cwg307: na
206 namespace cwg308 { // cwg308: 3.7
207 // This is mostly an ABI library issue.
208 struct A {};
209 struct B : A {};
210 struct C : A {};
211 struct D : B, C {};
212 void f() {
213 // NB: the warning here is correct despite being the opposite of the
214 // comments in the catch handlers. The "unreachable" comment is correct
215 // because there is an ambiguous base path to A from the D that is thrown.
216 // The warnings generated are also correct because the handlers handle
217 // const B& and const A& and we don't check to see if other derived classes
218 // exist that would cause an ambiguous base path. We issue the diagnostic
219 // despite the potential for a false positive because users are not
220 // expected to have ambiguous base paths all that often, so the false
221 // positive rate should be acceptably low.
222 try {
223 throw D();
224 } catch (const A&) { // #cwg308-catch-A
225 // unreachable
226 } catch (const B&) {
227 // expected-warning@-1 {{exception of type 'const B &' will be caught by earlier handler}}
228 // expected-note@#cwg308-catch-A {{for type 'const A &'}}
229 // get here instead
234 // cwg309: dup 485
236 namespace cwg311 { // cwg311: 3.0
237 namespace X { namespace Y {} }
238 namespace X::Y {}
239 // cxx98-14-error@-1 {{nested namespace definition is a C++17 extension; define each namespace separately}}
240 namespace X {
241 namespace X::Y {}
242 // cxx98-14-error@-1 {{nested namespace definition is a C++17 extension; define each namespace separately}}
244 // FIXME: The diagnostics here are not very good.
245 namespace ::cwg311::X {}
246 // expected-error@-1 {{expected identifier or '{'}}
247 // expected-warning@-2 {{extra qualification on member 'X'}}
248 // expected-error@-3 {{a type specifier is required for all declarations}}
249 // expected-error@-4 {{expected ';' after top level declarator}}
252 // cwg312: dup 616
254 namespace cwg313 { // cwg313: dup 299 c++11
255 struct A { operator int() const; };
256 // FIXME: should this be available in c++98 mode?
257 int *p = new int[A()];
258 // cxx98-error@-1 {{implicit conversion from array size expression of type 'A' to integral type 'int' is a C++11 extension}}
261 namespace cwg314 { // cwg314: no
262 // NB: dup 1710
263 template <typename T> struct A {
264 template <typename U> struct B {};
266 template <typename T> struct C : public A<T>::template B<T> {
267 C() : A<T>::template B<T>() {}
269 template <typename T> struct C2 : public A<T>::B<T> {
270 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
271 C2() : A<T>::B<T>() {}
272 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
274 } // namespace cwg314
276 // cwg315: na
277 // cwg316: sup 1004
279 namespace cwg317 { // cwg317: 3.5
280 void f() {} // #cwg317-f
281 inline void f();
282 // expected-error@-1 {{inline declaration of 'f' follows non-inline definition}}
283 // expected-note@#cwg317-f {{previous definition is here}}
285 int g();
286 int n = g();
287 inline int g() { return 0; }
289 int h();
290 int m = h();
291 int h() { return 0; } // #cwg317-h
292 inline int h();
293 // expected-error@-1 {{inline declaration of 'h' follows non-inline definition}}
294 // expected-note@#cwg317-h {{previous definition is here}}
297 namespace cwg318 { // cwg318: sup 1310
298 struct A {};
299 struct A::A a;
302 namespace cwg319 { // cwg319: no
303 // FIXME: dup cwg389
304 // FIXME: We don't have a diagnostic for a name with linkage
305 // having a type without linkage.
306 typedef struct {
307 int i;
308 } *ps;
309 extern "C" void f(ps);
310 void g(ps); // FIXME: ill-formed, type 'ps' has no linkage
312 static enum { e } a1;
313 enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage
315 enum { n1 = 1u };
316 typedef int (*pa)[n1];
317 pa parr; // ok, type has linkage despite using 'n1'
319 template<typename> struct X {};
321 void f() {
322 struct A { int n; };
323 extern A a; // FIXME: ill-formed
324 X<A> xa;
325 // cxx98-error@-1 {{template argument uses local type 'A'}}
327 typedef A B;
328 extern B b; // FIXME: ill-formed
329 X<B> xb;
330 // cxx98-error@-1 {{template argument uses local type 'A'}}
332 const int n = 1;
333 typedef int (*C)[n];
334 extern C c; // ok
335 X<C> xc;
339 namespace cwg320 { // cwg320: yes
340 #if __cplusplus >= 201103L
341 struct X {
342 constexpr X() {}
343 constexpr X(const X &x) : copies(x.copies + 1) {}
344 unsigned copies = 0;
346 constexpr X f(X x) { return x; }
347 constexpr unsigned g(X x) { return x.copies; }
348 static_assert(f(X()).copies == g(X()) + 1, "expected one extra copy for return value");
349 #endif
352 namespace cwg321 { // cwg321: dup 557
353 namespace N {
354 template<int> struct A {
355 template<int> struct B;
357 template<> template<> struct A<0>::B<0>;
358 void f(A<0>::B<0>);
360 template<> template<> struct N::A<0>::B<0> {};
362 template<typename T> void g(T t) { f(t); }
363 template void g(N::A<0>::B<0>);
365 namespace N {
366 template<typename> struct I { friend bool operator==(const I&, const I&); };
368 N::I<int> i, j;
369 bool x = i == j;
372 namespace cwg322 { // cwg322: 2.8
373 struct A {
374 template<typename T> operator T&();
375 } a;
376 int &r = static_cast<int&>(a);
377 int &s = a;
380 // cwg323: sup 820
382 namespace cwg324 { // cwg324: 3.6
383 struct S { int n : 1; } s; // #cwg324-n
384 int &a = s.n;
385 // expected-error@-1 {{non-const reference cannot bind to bit-field 'n'}}
386 // expected-note@#cwg324-n {{bit-field is declared here}}
387 int *b = &s.n;
388 // expected-error@-1 {{address of bit-field requested}}
389 int &c = (s.n = 0);
390 // expected-error@-1 {{non-const reference cannot bind to bit-field 'n'}}
391 // expected-note@#cwg324-n {{bit-field is declared here}}
392 int *d = &(s.n = 0);
393 // expected-error@-1 {{address of bit-field requested}}
394 // FIXME: why don't we emit a note here, as for the rest of this type of diagnostic in this test?
395 int &e = true ? s.n : s.n;
396 // expected-error@-1 {{non-const reference cannot bind to bit-field}}
397 int *f = &(true ? s.n : s.n);
398 // expected-error@-1 {{address of bit-field requested}}
399 int &g = (void(), s.n);
400 // expected-error@-1 {{non-const reference cannot bind to bit-field 'n'}}
401 // expected-note@#cwg324-n {{bit-field is declared here}}
402 int *h = &(void(), s.n);
403 // expected-error@-1 {{address of bit-field requested}}
404 int *i = &++s.n;
405 // expected-error@-1 {{address of bit-field requested}}
408 namespace cwg326 { // cwg326: 3.1
409 struct S {};
410 static_assert(__is_trivially_constructible(S, const S&), "");
413 namespace cwg327 { // cwg327: dup 538
414 struct A;
415 class A {};
417 class B;
418 struct B {};
421 namespace cwg328 { // cwg328: yes
422 struct A; // #cwg328-A
423 struct B { A a; };
424 // expected-error@-1 {{field has incomplete type 'A'}}
425 // expected-note@#cwg328-A {{forward declaration of 'cwg328::A'}}
426 template<typename> struct C { A a; };
427 // expected-error@-1 {{field has incomplete type 'A'}}
428 // expected-note@#cwg328-A {{forward declaration of 'cwg328::A'}}
429 A *p = new A[0];
430 // expected-error@-1 {{allocation of incomplete type 'A'}}
431 // expected-note@#cwg328-A {{forward declaration of 'cwg328::A'}}
434 namespace cwg329 { // cwg329: 3.5
435 struct B {};
436 template<typename T> struct A : B {
437 friend void f(A a) { g(a); }
438 friend void h(A a) { g(a); }
439 // expected-error@-1 {{use of undeclared identifier 'g'}}
440 // expected-note@#cwg329-h-call {{in instantiation of member function 'cwg329::h' requested here}}
441 friend void i(B b) {} // #cwg329-i
442 // expected-error@-1 {{redefinition of 'i'}}
443 // expected-note@#cwg329-b {{in instantiation of template class 'cwg329::A<char>' requested here}}
444 // expected-note@#cwg329-i {{previous definition is here}}
446 A<int> a;
447 A<char> b; // #cwg329-b
449 void test() {
450 h(a); // #cwg329-h-call
454 namespace cwg330 { // cwg330: 7
455 // Conversions between P and Q will be allowed by P0388.
456 typedef int *(*P)[3];
457 typedef const int *const (*Q)[3];
458 typedef const int *Qinner[3];
459 typedef Qinner const *Q2; // same as Q, but 'const' written outside the array type
460 typedef const int *const (*R)[4];
461 typedef const int *const (*S)[];
462 typedef const int *(*T)[];
463 void f(P p, Q q, Q2 q2, R r, S s, T t) {
464 q = p; // ok
465 q2 = p; // ok
466 r = p;
467 // expected-error@-1 {{incompatible pointer types assigning to 'R' (aka 'const int *const (*)[4]') from 'P' (aka 'int *(*)[3]')}}
468 s = p;
469 // cxx98-17-error@-1 {{incompatible pointer types assigning to 'S' (aka 'const int *const (*)[]') from 'P' (aka 'int *(*)[3]')}} (fixed by p0388)
470 t = p;
471 // expected-error@-1 {{incompatible pointer types assigning to 'T' (aka 'const int *(*)[]') from 'P' (aka 'int *(*)[3]')}}
472 s = q;
473 // cxx98-17-error@-1 {{incompatible pointer types assigning to 'S' (aka 'const int *const (*)[]') from 'Q' (aka 'const int *const (*)[3]')}} (fixed by p0388)
474 s = q2;
475 // cxx98-17-error@-1 {{incompatible pointer types assigning to 'S' (aka 'const int *const (*)[]') from 'Q2' (aka 'const int *const (*)[3]')}} (fixed by p0388)
476 s = t; // ok, adding const
477 t = s;
478 // expected-error@-1 {{assigning to 'T' (aka 'const int *(*)[]') from 'S' (aka 'const int *const (*)[]') discards qualifiers}}
479 (void) const_cast<P>(q);
480 (void) const_cast<P>(q2);
481 (void) const_cast<Q>(p);
482 (void) const_cast<Q2>(p);
483 (void) const_cast<S>(p);
484 // expected-error@-1 {{const_cast from 'P' (aka 'int *(*)[3]') to 'S' (aka 'const int *const (*)[]') is not allowed}} (for now)
485 (void) const_cast<P>(s);
486 // expected-error@-1 {{const_cast from 'S' (aka 'const int *const (*)[]') to 'P' (aka 'int *(*)[3]') is not allowed}} (for now)
487 (void) const_cast<S>(q);
488 // expected-error@-1 {{const_cast from 'Q' (aka 'const int *const (*)[3]') to 'S' (aka 'const int *const (*)[]') is not allowed}}
489 (void) const_cast<S>(q2);
490 // expected-error@-1 {{const_cast from 'Q2' (aka 'const int *const (*)[3]') to 'S' (aka 'const int *const (*)[]') is not allowed}}
491 (void) const_cast<Q>(s);
492 // expected-error@-1 {{const_cast from 'S' (aka 'const int *const (*)[]') to 'Q' (aka 'const int *const (*)[3]') is not allowed}}
493 (void) const_cast<Q2>(s);
494 // expected-error@-1 {{const_cast from 'S' (aka 'const int *const (*)[]') to 'Q2' (aka 'const int *const (*)[3]') is not allowed}}
495 (void) const_cast<T>(s);
496 (void) const_cast<S>(t);
497 (void) const_cast<T>(q);
498 // expected-error@-1 {{const_cast from 'Q' (aka 'const int *const (*)[3]') to 'T' (aka 'const int *(*)[]') is not allowed}}
499 (void) const_cast<Q>(t);
500 // expected-error@-1 {{const_cast from 'T' (aka 'const int *(*)[]') to 'Q' (aka 'const int *const (*)[3]') is not allowed}}
502 (void) reinterpret_cast<P>(q);
503 // expected-error@-1 {{reinterpret_cast from 'Q' (aka 'const int *const (*)[3]') to 'P' (aka 'int *(*)[3]') casts away qualifiers}}
504 (void) reinterpret_cast<P>(q2);
505 // expected-error@-1 {{reinterpret_cast from 'Q2' (aka 'const int *const (*)[3]') to 'P' (aka 'int *(*)[3]') casts away qualifiers}}
506 (void) reinterpret_cast<Q>(p);
507 (void) reinterpret_cast<Q2>(p);
508 (void) reinterpret_cast<S>(p);
509 (void) reinterpret_cast<P>(s);
510 // expected-error@-1 {{reinterpret_cast from 'S' (aka 'const int *const (*)[]') to 'P' (aka 'int *(*)[3]') casts away qualifiers}}
511 (void) reinterpret_cast<S>(q);
512 (void) reinterpret_cast<S>(q2);
513 (void) reinterpret_cast<Q>(s);
514 (void) reinterpret_cast<Q2>(s);
515 (void) reinterpret_cast<T>(s);
516 // expected-error@-1 {{reinterpret_cast from 'S' (aka 'const int *const (*)[]') to 'T' (aka 'const int *(*)[]') casts away qualifiers}}
517 (void) reinterpret_cast<S>(t);
518 (void) reinterpret_cast<T>(q);
519 // expected-error@-1 {{reinterpret_cast from 'Q' (aka 'const int *const (*)[3]') to 'T' (aka 'const int *(*)[]') casts away qualifiers}}
520 (void) reinterpret_cast<Q>(t);
523 namespace swift_17882 {
524 typedef const char P[72];
525 typedef int *Q;
526 void f(P &pr, P *pp) {
527 (void) reinterpret_cast<const Q&>(pr);
528 (void) reinterpret_cast<const Q*>(pp);
531 struct X {};
532 typedef const volatile int A[1][2][3];
533 typedef int *const X::*volatile *B1;
534 typedef int *const X::* *B2;
535 typedef int *X::* volatile *B3;
536 typedef volatile int *(*const B4)[4];
537 void f(A *a) {
538 (void) reinterpret_cast<B1*>(a);
539 (void) reinterpret_cast<B2*>(a);
540 // expected-error@-1 {{ISO C++ does not allow reinterpret_cast from 'A *' (aka 'const volatile int (*)[1][2][3]') to 'B2 *' (aka 'int *const cwg330::swift_17882::X::***') because it casts away qualifiers, even though the source and destination types are unrelated}}
541 (void) reinterpret_cast<B3*>(a);
542 // expected-error@-1 {{ISO C++ does not allow reinterpret_cast from 'A *' (aka 'const volatile int (*)[1][2][3]') to 'B3 *' (aka 'int *cwg330::swift_17882::X::*volatile **') because it casts away qualifiers, even though the source and destination types are unrelated}}
543 (void) reinterpret_cast<B4*>(a);
548 namespace cwg331 { // cwg331: 11
549 struct A {
550 A(volatile A&); // #cwg331-A-ctor
552 const A a;
553 // expected-error@-1 {{no matching constructor for initialization of 'const A'}}
554 // expected-note@#cwg331-A-ctor {{candidate constructor not viable: requires 1 argument, but 0 were provided}}
555 const A b(a);
556 // expected-error@-1 {{no matching constructor for initialization of 'const A'}}
557 // expected-note@#cwg331-A-ctor {{candidate constructor not viable: 1st argument ('const A') would lose const qualifier}}
560 namespace cwg332 { // cwg332: dup 577
561 void f(volatile void);
562 // expected-error@-1 {{'void' as parameter must not have type qualifiers}}
563 // cxx20-23-warning@-2 {{volatile-qualified parameter type 'volatile void' is deprecated}}
564 void g(const void);
565 // expected-error@-1 {{'void' as parameter must not have type qualifiers}}
566 void h(int n, volatile void);
567 // expected-error@-1 {{'void' must be the first and only parameter if specified}}
568 // cxx20-23-warning@-2 {{volatile-qualified parameter type 'volatile void' is deprecated}}
571 namespace cwg333 { // cwg333: yes
572 int n = 0;
573 int f(int(n));
574 int g((int(n)));
575 int h = f(g);
578 namespace cwg334 { // cwg334: yes
579 template<typename T> void f() {
580 T x;
581 f((x, 123));
583 struct S {
584 friend S operator,(S, int);
585 friend void f(S);
587 template void f<S>();
590 // cwg335: sup 820
592 namespace cwg336 { // cwg336: yes
593 namespace Pre {
594 template<class T1> class A {
595 template<class T2> class B {
596 template<class T3> void mf1(T3);
597 void mf2();
600 template<> template<class X> class A<int>::B {}; // #cwg336-B
601 template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {}
602 // expected-error@-1 {{out-of-line definition of 'mf1' does not match any declaration in 'cwg336::Pre::A<int>::B<double>'}}
603 // expected-note@#cwg336-B {{defined here}}
604 template<class Y> template<> void A<Y>::B<double>::mf2() {}
605 // expected-error@-1 {{nested name specifier 'A<Y>::B<double>::' for declaration does not refer into a class, class template or class template partial specialization}}
607 namespace Post {
608 template<class T1> class A {
609 template<class T2> class B {
610 template<class T3> void mf1(T3);
611 void mf2();
614 template<> template<class X> class A<int>::B {
615 template<class T> void mf1(T);
617 template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {}
618 // FIXME: This diagnostic isn't very good.
619 template<class Y> template<> void A<Y>::B<double>::mf2() {}
620 // expected-error@-1 {{nested name specifier 'A<Y>::B<double>::' for declaration does not refer into a class, class template or class template partial specialization}}
624 namespace cwg337 { // cwg337: yes
625 template<typename T> void f(T (*)[1]);
626 template<typename T> int &f(...);
628 struct A { virtual ~A() = 0; };
629 int &r = f<A>(0);
631 // FIXME: The language rules here are completely broken. We cannot determine
632 // whether an incomplete type is abstract. See CWG1640, which will probably
633 // supersede this one and remove this rule.
634 struct B;
635 int &s = f<B>(0);
636 // expected-error@-1 {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'void'}}
637 struct B { virtual ~B() = 0; };
640 // cwg338: dup 1884
642 namespace cwg339 { // cwg339: 2.8
643 template <int I> struct A { static const int value = I; };
645 char xxx(int);
646 char (&xxx(float))[2];
648 template<class T> A<sizeof(xxx((T)0))> f(T) {} // #cwg339-f
650 void test() {
651 A<1> a = f(0);
652 A<2> b = f(0.0f);
653 A<3> c = f("foo");
654 // expected-error@-1 {{no matching function}}
655 // expected-note@#cwg339-f {{candidate}}
659 char f(int);
660 int f(...);
662 template <class T> struct conv_int {
663 static const bool value = sizeof(f(T())) == 1;
666 template <class T> bool conv_int2(A<sizeof(f(T()))> p);
668 template<typename T> A<sizeof(f(T()))> make_A();
670 static_assert(conv_int<char>::value, "");
671 bool b = conv_int2<char>(A<1>());
672 A<1> c = make_A<char>();
675 namespace cwg340 { // cwg340: yes
676 struct A { A(int); };
677 struct B { B(A, A, int); };
678 int x, y;
679 B b(A(x), A(y), 3);
682 namespace cwg341 { // cwg341: sup 1708
683 namespace A {
684 int n;
685 extern "C" int &cwg341_a = n; // #cwg341_a
687 namespace B {
688 extern "C" int &cwg341_a = cwg341_a;
689 // expected-error@-1 {{redefinition of 'cwg341_a'}}
690 // expected-note@#cwg341_a {{previous definition is here}}
692 extern "C" void cwg341_b(); // #cwg341_b
694 int cwg341_a;
695 // expected-error@-1 {{declaration of 'cwg341_a' in global scope conflicts with declaration with C language linkage}}
696 // expected-note@#cwg341_a {{declared with C language linkage here}}
697 int cwg341_b;
698 // expected-error@-1 {{declaration of 'cwg341_b' in global scope conflicts with declaration with C language linkage}}
699 // expected-note@#cwg341_b {{declared with C language linkage here}}
700 int cwg341_c; // #cwg341_c
701 int cwg341_d; // #cwg341_d
702 namespace cwg341 {
703 extern "C" int cwg341_c;
704 // expected-error@-1 {{declaration of 'cwg341_c' with C language linkage conflicts with declaration in global scope}}
705 // expected-note@#cwg341_c {{declared in global scope here}}
706 extern "C" void cwg341_d();
707 // expected-error@-1 {{declaration of 'cwg341_d' with C language linkage conflicts with declaration in global scope}}
708 // expected-note@#cwg341_d {{declared in global scope here}}
710 namespace A { extern "C" int cwg341_e; } // #cwg341_e
711 namespace B { extern "C" void cwg341_e(); }
712 // expected-error@-1 {{redefinition of 'cwg341_e' as different kind of symbol}}
713 // expected-note@#cwg341_e {{previous definition is here}}
716 // cwg342: na
718 namespace cwg343 { // cwg343: no
719 // FIXME: dup 1710
720 template<typename T> struct A {
721 template<typename U> struct B {};
723 // FIXME: In these contexts, the 'template' keyword is optional.
724 template<typename T> struct C : public A<T>::B<T> {
725 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
726 C() : A<T>::B<T>() {}
727 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
731 namespace cwg344 { // cwg344: dup 1435
732 struct A { inline virtual ~A(); };
733 struct B { friend A::~A(); };
736 namespace cwg345 { // cwg345: yes
737 struct A {
738 struct X {};
739 int X; // #cwg345-int-X
741 struct B {
742 struct X {};
744 template <class T> void f(T t) { typename T::X x; }
745 // expected-error@-1 {{typename specifier refers to non-type member 'X' in 'cwg345::A'}}
746 // expected-note@#cwg345-f-a {{in instantiation of function template specialization 'cwg345::f<cwg345::A>' requested here}}
747 // expected-note@#cwg345-int-X {{referenced member 'X' is declared here}}
748 void f(A a, B b) {
749 f(b);
750 f(a); // #cwg345-f-a
754 // cwg346: na
756 namespace cwg347 { // cwg347: yes
757 struct base {
758 struct nested;
759 static int n;
760 static void f();
761 void g();
764 struct derived : base {}; // #cwg347-derived
766 struct derived::nested {};
767 // expected-error@-1 {{no struct named 'nested' in 'cwg347::derived'}}
768 int derived::n;
769 // expected-error@-1 {{no member named 'n' in 'cwg347::derived'}}
770 void derived::f() {}
771 // expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'cwg347::derived'}}
772 // expected-note@#cwg347-derived {{defined here}}
773 void derived::g() {}
774 // expected-error@-1 {{out-of-line definition of 'g' does not match any declaration in 'cwg347::derived'}}
775 // expected-note@#cwg347-derived {{defined here}}
778 // cwg348: na
780 namespace cwg349 { // cwg349: no
781 struct A {
782 template <class T> operator T ***() {
783 int ***p = 0;
784 return p;
785 // cxx98-20-error@-1 {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}}
786 // since-cxx23-error@-2 {{cannot initialize return object of type 'const int ***' with an rvalue of type 'int ***'}}
787 // expected-note@#cwg349-p1 {{in instantiation of function template specialization 'cwg349::A::operator const int ***<const int>' requested here}}
791 // FIXME: This is valid.
792 A a;
793 const int *const *const *p1 = a; // #cwg349-p1
795 struct B {
796 template <class T> operator T ***() {
797 const int ***p = 0;
798 return p;
802 // FIXME: This is invalid.
803 B b;
804 const int *const *const *p2 = b;
807 // cwg351: na
809 namespace cwg352 { // cwg352: 2.8
810 namespace example1 {
811 namespace A {
812 enum E {};
813 template<typename R, typename A> void foo(E, R (*)(A)); // #cwg352-foo
816 template<typename T> void arg(T);
817 template<typename T> int arg(T) = delete; // #cwg352-deleted
818 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
820 void f(A::E e) {
821 foo(e, &arg);
822 // expected-error@-1 {{no matching function for call to 'foo'}}
823 // expected-note@#cwg352-foo {{candidate template ignored: couldn't infer template argument 'R'}}
825 using A::foo;
826 foo<int, int>(e, &arg);
827 // expected-error@-1 {{attempt to use a deleted function}}
828 // expected-note@#cwg352-deleted {{'arg<int>' has been explicitly marked deleted here}}
831 int arg(int);
833 void g(A::E e) {
834 foo(e, &arg);
835 // expected-error@-1 {{no matching function for call to 'foo'}}
836 // expected-note@#cwg352-foo {{candidate template ignored: couldn't infer template argument 'R'}}
838 using A::foo;
839 foo<int, int>(e, &arg); // ok, uses non-template
843 namespace contexts {
844 template<int I> void f1(int (&)[I]);
845 template<int I> void f2(int (&)[I+1]); // #cwg352-f2
846 template<int I> void f3(int (&)[I+1], int (&)[I]);
847 void f() {
848 int a[4];
849 int b[3];
850 f1(a);
851 f2(a);
852 // expected-error@-1 {{no matching function for call to 'f2'}}
853 // expected-note@#cwg352-f2 {{candidate template ignored: couldn't infer template argument 'I'}}
854 f3(a, b);
857 template<int I> struct S {};
858 template<int I> void g1(S<I>);
859 template<int I> void g2(S<I+1>); // #cwg352-g2
860 template<int I> void g3(S<I+1>, S<I>);
861 void g() {
862 S<4> a;
863 S<3> b;
864 g1(a);
865 g2(a);
866 // expected-error@-1 {{no matching function for call to 'g2'}}
867 // expected-note@#cwg352-g2 {{candidate template ignored: couldn't infer template argument 'I'}}
868 g3(a, b);
871 template<typename T> void h1(T = 0); // #cwg352-h1
872 template<typename T> void h2(T, T = 0);
873 void h() {
874 h1();
875 // expected-error@-1 {{no matching function for call to 'h1'}}
876 // expected-note@#cwg352-h1 {{candidate template ignored: couldn't infer template argument 'T'}}
877 h1(0);
878 h1<int>();
879 h2(0);
882 template<typename T> int tmpl(T);
883 template<typename R, typename A> void i1(R (*)(A)); // #cwg352-i1
884 template<typename R, typename A> void i2(R, A, R (*)(A)); // #cwg352-i2
885 void i() {
886 extern int single(int);
887 i1(single);
888 i2(0, 0, single);
890 extern int ambig(float), ambig(int);
891 i1(ambig);
892 // expected-error@-1 {{no matching function for call to 'i1'}}
893 // expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}}
894 i2(0, 0, ambig);
896 extern void no_match(float), no_match(int);
897 i1(no_match);
898 // expected-error@-1 {{no matching function for call to 'i1'}}
899 // expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}}
900 i2(0, 0, no_match);
901 // expected-error@-1 {{no matching function for call to 'i2'}}
902 // expected-note@#cwg352-i2 {{candidate function [with R = int, A = int] not viable: no overload of 'no_match' matching 'int (*)(int)' for 3rd argument}}
904 i1(tmpl);
905 // expected-error@-1 {{no matching function for call to 'i1'}}
906 // expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}}
907 i2(0, 0, tmpl);
911 template<typename T> struct is_int;
912 template<> struct is_int<int> {};
914 namespace example2 {
915 template<typename T> int f(T (*p)(T)) { is_int<T>(); }
916 int g(int);
917 int g(char);
918 int i = f(g);
921 namespace example3 {
922 template<typename T> int f(T, T (*p)(T)) { is_int<T>(); }
923 int g(int);
924 char g(char);
925 int i = f(1, g);
928 namespace example4 {
929 template <class T> int f(T, T (*p)(T)) { is_int<T>(); }
930 char g(char);
931 template <class T> T g(T);
932 int i = f(1, g);
935 namespace example5 {
936 template<int I> class A {};
937 template<int I> void g(A<I+1>); // #cwg352-g
938 template<int I> void f(A<I>, A<I+1>);
939 void h(A<1> a1, A<2> a2) {
940 g(a1);
941 // expected-error@-1 {{no matching function for call to 'g'}}
942 // expected-note@#cwg352-g {{candidate template ignored: couldn't infer template argument 'I'}}
943 g<0>(a1);
944 f(a1, a2);
949 // cwg353 needs an IRGen test.
951 namespace cwg354 { // cwg354: yes c++11
952 // FIXME: Should we allow this in C++98 too?
953 struct S {};
955 template<int*> struct ptr {}; // #cwg354-ptr
956 ptr<0> p0; // #cwg354-p0
957 // cxx98-error@#cwg354-p0 {{non-type template argument does not refer to any declaration}}
958 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
959 // cxx11-14-error@#cwg354-p0 {{null non-type template argument must be cast to template parameter type 'int *'}}
960 // cxx11-14-note@#cwg354-ptr {{template parameter is declared here}}
961 // since-cxx17-error@#cwg354-p0 {{conversion from 'int' to 'int *' is not allowed in a converted constant expression}}
962 ptr<(int*)0> p1;
963 // cxx98-error@-1 {{non-type template argument does not refer to any declaration}}
964 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
965 ptr<(float*)0> p2; // #cwg354-p2
966 // cxx98-error@#cwg354-p2 {{non-type template argument does not refer to any declaration}}
967 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
968 // cxx11-14-error@#cwg354-p2 {{null non-type template argument of type 'float *' does not match template parameter of type 'int *'}}
969 // cxx11-14-note@#cwg354-ptr {{template parameter is declared here}}
970 // since-cxx17-error@#cwg354-p2 {{value of type 'float *' is not implicitly convertible to 'int *'}}
971 ptr<(int S::*)0> p3; // #cwg354-p3
972 // cxx98-error@#cwg354-p3 {{non-type template argument does not refer to any declaration}}
973 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
974 // cxx11-14-error@#cwg354-p3 {{null non-type template argument of type 'int cwg354::S::*' does not match template parameter of type 'int *'}}
975 // cxx11-14-note@#cwg354-ptr {{template parameter is declared here}}
976 // since-cxx17-error@#cwg354-p3 {{value of type 'int cwg354::S::*' is not implicitly convertible to 'int *'}}
978 template<int*> int both(); // #cwg354-both-int-ptr
979 template<int> int both(); // #cwg354-both-int
980 int b0 = both<0>();
981 int b1 = both<(int*)0>();
982 // cxx98-error@-1 {{no matching function for call to 'both'}}
983 // cxx98-note@#cwg354-both-int-ptr {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
984 // cxx98-note@#cwg354-both-int {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
986 template<int S::*> struct ptr_mem {}; // #cwg354-ptr_mem
987 ptr_mem<0> m0; // #cwg354-m0
988 // cxx98-error@#cwg354-m0 {{non-type template argument of type 'int' cannot be converted to a value of type 'int cwg354::S::*'}}
989 // cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}}
990 // cxx11-14-error@#cwg354-m0 {{null non-type template argument must be cast to template parameter type 'int cwg354::S::*'}}
991 // cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}}
992 // since-cxx17-error@#cwg354-m0 {{conversion from 'int' to 'int cwg354::S::*' is not allowed in a converted constant expression}}
993 ptr_mem<(int S::*)0> m1;
994 // cxx98-error@-1 {{non-type template argument is not a pointer to member constant}}
995 ptr_mem<(float S::*)0> m2; // #cwg354-m2
996 // cxx98-error@#cwg354-m2 {{non-type template argument of type 'float cwg354::S::*' cannot be converted to a value of type 'int cwg354::S::*'}}
997 // cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}}
998 // cxx11-14-error@#cwg354-m2 {{null non-type template argument of type 'float cwg354::S::*' does not match template parameter of type 'int cwg354::S::*'}}
999 // cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}}
1000 // since-cxx17-error@#cwg354-m2 {{value of type 'float cwg354::S::*' is not implicitly convertible to 'int cwg354::S::*'}}
1001 ptr_mem<(int *)0> m3; // #cwg354-m3
1002 // cxx98-error@#cwg354-m3 {{non-type template argument of type 'int *' cannot be converted to a value of type 'int cwg354::S::*'}}
1003 // cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}}
1004 // cxx11-14-error@#cwg354-m3 {{null non-type template argument of type 'int *' does not match template parameter of type 'int cwg354::S::*'}}
1005 // cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}}
1006 // since-cxx17-error@#cwg354-m3 {{value of type 'int *' is not implicitly convertible to 'int cwg354::S::*'}}
1009 struct cwg355_S; // cwg355: yes
1010 struct ::cwg355_S {};
1011 // expected-warning@-1 {{extra qualification on member 'cwg355_S'}}
1012 namespace cwg355 { struct ::cwg355_S s; }
1014 // cwg356: na
1016 namespace cwg357 { // cwg357: yes
1017 template<typename T> struct A { // #cwg357-A
1018 void f() const; // #cwg357-f
1020 template<typename T> void A<T>::f() {}
1021 // expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'A<T>'}}
1022 // expected-note@#cwg357-A {{defined here}}
1023 // expected-note@#cwg357-f {{member declaration does not match because it is const qualified}}
1025 struct B { // #cwg357-B
1026 template<typename T> void f();
1028 template<typename T> void B::f() const {}
1029 // expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'cwg357::B'}}
1030 // expected-note@#cwg357-B {{defined here}}
1033 namespace cwg358 { // cwg358: yes
1034 extern "C" void cwg358_f();
1035 namespace N {
1036 int var;
1037 extern "C" void cwg358_f() { var = 10; }
1041 namespace cwg359 { // cwg359: yes
1042 // Note, the example in the DR is wrong; it doesn't contain an anonymous
1043 // union.
1044 struct E {
1045 union {
1046 struct {
1047 int x;
1048 } s;
1049 } v;
1051 union {
1052 struct {
1053 // expected-error@-1 {{anonymous types declared in an anonymous union are an extension}}
1054 int x;
1055 } s;
1057 struct S {
1058 // expected-error@-1 {{types cannot be declared in an anonymous union}}
1059 int x;
1060 } t;
1062 union {
1063 // expected-error@-1 {{anonymous types declared in an anonymous union are an extension}}
1064 int u;
1070 namespace cwg360 { // cwg360: yes
1071 struct A {
1072 int foo();
1073 int bar();
1075 protected:
1076 int baz();
1079 struct B : A {
1080 private:
1081 using A::foo; // #cwg360-using-foo
1082 protected:
1083 using A::bar; // #cwg360-using-bar
1084 public:
1085 using A::baz;
1088 int main() {
1089 int foo = B().foo();
1090 // expected-error@-1 {{'foo' is a private member of 'cwg360::B'}}
1091 // expected-note@#cwg360-using-foo {{declared private here}}
1092 int bar = B().bar();
1093 // expected-error@-1 {{'bar' is a protected member of 'cwg360::B'}}
1094 // expected-note@#cwg360-using-bar {{declared protected here}}
1095 int baz = B().baz();
1097 } // namespace cwg360
1099 // cwg362: na
1100 // cwg363: na
1102 namespace cwg364 { // cwg364: yes
1103 struct S {
1104 static void f(int);
1105 void f(char);
1108 void g() {
1109 S::f('a');
1110 // expected-error@-1 {{call to non-static member function without an object argument}}
1111 S::f(0);
1115 // cwg366: yes
1116 #if "foo" // expected-error {{invalid token at start of a preprocessor expression}}
1117 #endif
1119 namespace cwg367 { // cwg367: yes
1120 static_assert(__enable_constant_folding(true ? throw 0 : 4), "");
1121 // expected-error@-1 {{expression is not an integral constant expression}}
1122 static_assert(__enable_constant_folding(true ? 4 : throw 0), "");
1123 static_assert(__enable_constant_folding(true ? *new int : 4), "");
1124 // expected-error@-1 {{expression is not an integral constant expression}}
1125 // expected-note@-2 {{read of uninitialized object is not allowed in a constant expression}}
1126 static_assert(__enable_constant_folding(true ? 4 : *new int), "");
1130 namespace cwg368 { // cwg368: 3.6
1131 template<typename T, T> struct S {}; // #cwg368-S
1132 template<typename T> int f(S<T, T()> *);
1133 // expected-error@-1 {{template argument for non-type template parameter is treated as function type 'T ()'}}
1134 // expected-note@#cwg368-S {{template parameter is declared here}}
1135 template<typename T> int g(S<T, (T())> *); // #cwg368-g
1136 template<typename T> int g(S<T, true ? T() : T()> *); // #cwg368-g-2
1137 struct X {};
1138 int n = g<X>(0); // #cwg368-g-call
1139 // cxx98-17-error@#cwg368-g-call {{no matching function for call to 'g'}}
1140 // cxx98-17-note@#cwg368-g {{candidate template ignored: substitution failure [with T = X]: a non-type template parameter cannot have type 'X' before C++20}}
1141 // cxx98-17-note@#cwg368-g-2 {{candidate template ignored: substitution failure [with T = X]: a non-type template parameter cannot have type 'X' before C++20}}
1142 // cxx20-23-error@#cwg368-g-call {{call to 'g' is ambiguous}}
1143 // cxx20-23-note@#cwg368-g {{candidate function [with T = cwg368::X]}}
1144 // cxx20-23-note@#cwg368-g-2 {{candidate function [with T = cwg368::X]}}
1147 // cwg370: na
1149 namespace cwg372 { // cwg372: no
1150 namespace example1 {
1151 template<typename T> struct X {
1152 protected:
1153 typedef T Type; // #cwg372-ex1-Type
1155 template<typename T> struct Y {};
1157 // FIXME: These two are valid; deriving from T1<T> gives Z1 access to
1158 // the protected member T1<T>::Type.
1159 template<typename T,
1160 template<typename> class T1,
1161 template<typename> class T2> struct Z1 :
1162 T1<T>,
1163 T2<typename T1<T>::Type> {};
1164 // expected-error@-1 {{'Type' is a protected member of 'cwg372::example1::X<int>'}}
1165 // expected-note@#cwg372-z1 {{in instantiation of template class 'cwg372::example1::Z1<int, cwg372::example1::X, cwg372::example1::Y>' requested here}}
1166 // expected-note@#cwg372-ex1-Type {{declared protected here}}
1168 template<typename T,
1169 template<typename> class T1,
1170 template<typename> class T2> struct Z2 :
1171 T2<typename T1<T>::Type>,
1172 // expected-error@-1 {{'Type' is a protected member of 'cwg372::example1::X<int>'}}
1173 // expected-note@#cwg372-z2 {{in instantiation of template class 'cwg372::example1::Z2<int, cwg372::example1::X, cwg372::example1::Y>' requested here}}
1174 // expected-note@#cwg372-ex1-Type {{declared protected here}}
1175 T1<T> {};
1177 Z1<int, X, Y> z1; // #cwg372-z1
1178 Z2<int, X, Y> z2; // #cwg372-z2
1181 namespace example2 {
1182 struct X {
1183 private:
1184 typedef int Type; // #cwg372-ex2-Type
1186 template<typename T> struct A {
1187 typename T::Type t;
1188 // expected-error@-1 {{'Type' is a private member of 'cwg372::example2::X'}}
1189 // expected-note@#cwg372-ax {{in instantiation of template class 'cwg372::example2::A<cwg372::example2::X>' requested here}}
1190 // expected-note@#cwg372-ex2-Type {{declared private here}}
1192 A<X> ax; // #cwg372-ax
1195 namespace example3 {
1196 struct A {
1197 protected:
1198 typedef int N; // #cwg372-N
1201 template<typename T> struct B {};
1202 template<typename U> struct C : U, B<typename U::N> {};
1203 // expected-error@-1 {{'N' is a protected member of 'cwg372::example3::A'}}
1204 // expected-note@#cwg372-x {{in instantiation of template class 'cwg372::example3::C<cwg372::example3::A>' requested here}}
1205 // expected-note@#cwg372-N {{declared protected here}}
1206 template<typename U> struct D : B<typename U::N>, U {};
1207 // expected-error@-1 {{'N' is a protected member of 'cwg372::example3::A'}}
1208 // expected-note@#cwg372-y {{in instantiation of template class 'cwg372::example3::D<cwg372::example3::A>' requested here}}
1209 // expected-note@#cwg372-N {{declared protected here}}
1211 C<A> x; // #cwg372-x
1212 D<A> y; // #cwg372-y
1215 namespace example4 {
1216 class A {
1217 class B {};
1218 friend class X;
1221 struct X : A::B {
1222 A::B mx;
1223 class Y {
1224 A::B my;
1229 // FIXME: This is valid: deriving from A gives D access to A::B
1230 namespace std_example {
1231 class A {
1232 protected:
1233 struct B {}; // #cwg372-B-std
1235 struct D : A::B, A {};
1236 // expected-error@-1 {{'B' is a protected member of 'cwg372::std_example::A'}}
1237 // expected-note@#cwg372-B-std {{declared protected here}}
1240 // FIXME: This is valid: deriving from A::B gives access to A::B!
1241 namespace badwolf {
1242 class A {
1243 protected:
1244 struct B; // #cwg372-B
1246 struct A::B : A {};
1247 struct C : A::B {};
1248 // expected-error@-1 {{'B' is a protected member of 'cwg372::badwolf::A'}}
1249 // expected-note@#cwg372-B {{declared protected here}}
1253 namespace cwg373 { // cwg373: 5
1254 namespace X { int cwg373; }
1255 struct cwg373 { // #cwg373-struct
1256 void f() {
1257 using namespace cwg373::X;
1258 int k = cwg373;
1259 // expected-error@-1 {{'cwg373' does not refer to a value}}
1260 // expected-note@#cwg373-struct {{declared here}}
1261 namespace Y = cwg373::X;
1262 k = Y::cwg373;
1266 struct A { struct B {}; }; // #cwg373-A
1267 namespace X = A::B;
1268 // expected-error@-1 {{expected namespace name}}
1269 // expected-note@#cwg373-A {{'A' declared here}}
1270 using namespace A::B;
1271 // expected-error@-1 {{expected namespace name}}
1272 // expected-note@#cwg373-A {{'A' declared here}}
1275 namespace cwg374 { // cwg374: 7
1276 // NB 2.9 c++11
1277 namespace N {
1278 template<typename T> void f();
1279 template<typename T> struct A { void f(); };
1281 template<> void N::f<char>() {}
1282 template<> void N::A<char>::f() {}
1283 template<> struct N::A<int> {};
1286 // cwg375: dup 345
1287 // cwg376: na
1289 namespace cwg377 { // cwg377: yes
1290 enum E {
1291 // expected-error@-1 {{enumeration values exceed range of largest integer}}
1292 a = -__LONG_LONG_MAX__ - 1,
1293 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1294 b = 2 * (unsigned long long)__LONG_LONG_MAX__
1295 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1296 // cxx98-error@-2 {{'long long' is a C++11 extension}}
1300 // cwg378: dup 276
1301 // cwg379: na
1303 namespace cwg381 { // cwg381: yes
1304 struct A {
1305 int a;
1307 struct B : virtual A {};
1308 struct C : B {};
1309 struct D : B {};
1310 struct E : public C, public D {};
1311 struct F : public A {};
1312 void f() {
1313 E e;
1314 e.B::a = 0;
1315 /* expected-error@-1 {{ambiguous conversion from derived class 'E' to base class 'cwg381::B':
1316 struct cwg381::E -> C -> B
1317 struct cwg381::E -> D -> B}} */
1318 F f;
1319 f.A::a = 1;
1323 namespace cwg382 { // cwg382: yes c++11
1324 // FIXME: Should we allow this in C++98 mode?
1325 struct A { typedef int T; };
1326 typename A::T t;
1327 // cxx98-error@-1 {{'typename' occurs outside of a template}}
1328 typename cwg382::A a;
1329 // cxx98-error@-1 {{'typename' occurs outside of a template}}
1330 typename A b;
1331 // expected-error@-1 {{expected a qualified name after 'typename'}}
1334 namespace cwg383 { // cwg383: yes
1335 struct A { A &operator=(const A&); };
1336 struct B { ~B(); };
1337 union C { C &operator=(const C&); };
1338 union D { ~D(); };
1339 static_assert(!__is_pod(A) && !__is_pod(B) && !__is_pod(C) && !__is_pod(D), "");
1342 namespace cwg384 { // cwg384: yes
1343 namespace N1 {
1344 template<typename T> struct Base {};
1345 template<typename T> struct X {
1346 struct Y : public Base<T> {
1347 Y operator+(int) const;
1349 Y f(unsigned i) { return Y() + i; }
1353 namespace N2 {
1354 struct Z {};
1355 template<typename T> int *operator+(T, unsigned);
1358 int main() {
1359 N1::X<N2::Z> v;
1360 v.f(0);
1364 namespace cwg385 { // cwg385: 2.8
1365 struct A { protected: void f(); };
1366 struct B : A { using A::f; };
1367 struct C : A { void g(B b) { b.f(); } };
1368 void h(B b) { b.f(); }
1370 struct D { int n; }; // #cwg385-n
1371 struct E : protected D {}; // #cwg385-E
1372 struct F : E { friend int i(E); };
1373 int i(E e) { return e.n; }
1374 // expected-error@-1 {{'n' is a protected member of 'cwg385::D'}}
1375 // expected-note@#cwg385-E {{constrained by protected inheritance here}}
1376 // expected-note@#cwg385-n {{member is declared here}}
1379 namespace cwg386 { // cwg386: no
1380 namespace example1 {
1381 namespace N1 {
1382 // Binds name 'f' in N1. Target scope is N1.
1383 template<typename T> void f( T* x ) {
1384 // ... other stuff ...
1385 delete x;
1389 namespace N2 {
1390 // Bind name 'f' in N2. When a single search find this declaration,
1391 // it's replaced with N1::f declaration.
1392 using N1::f;
1394 // According to _N4988_.[dcl.meaning]/3.3:
1395 // `f<int>` is not a qualified-id, so its target scope is N2.
1396 // `f<int>` is a template-id, so 'f' undergoes (unqualified) lookup.
1397 // Search performed by unqualified lookup finds N1::f via using-declaration,
1398 // but this result is not considered, because it's not nominable in N2,
1399 // which is because its target scope is N1.
1400 // So unqualified lookup doesn't find anything, making this declaration ill-formed.
1401 template<> void f<int>( int* );
1402 // expected-error@-1 {{no function template matches function template specialization 'f'}}
1404 class Test {
1405 ~Test() { }
1406 // According to _N4988_.[dcl.meaning]/2.2:
1407 // `f<>` is a template-id and not a template declaration,
1408 // so its terminal name 'f' undergoes (unqualified) lookup.
1409 // Search in N2 performed by unqualified lookup finds
1410 // (single) N1::f declaration via using-declaration.
1411 // N1::f is replaced with N1::f<> specialization after deduction,
1412 // and this is the result of the unqualified lookup.
1413 // This friend declaration correspond to the result of the lookup.
1414 // All lookup results target the same scope, which is N1,
1415 // so target scope of this friend declaration is also N1.
1416 // FIXME: This is well-formed.
1417 friend void f<>( Test* x );
1418 // expected-error@-1 {{no function template matches function template specialization 'f'}}
1421 } // namespace example1
1423 namespace example2 {
1424 namespace N1 {
1425 // Binds name 'f' in N1. Target scope is N1.
1426 void f(); // #cwg386-ex2-N1-f
1429 namespace N2 {
1430 // Bind name 'f' in N2. When a single search finds this declaration,
1431 // it's replaced with N1::f declaration.
1432 using N1::f; // #cwg386-ex2-using
1433 class A {
1434 // According to _N4988_.[dcl.meaning]/2.2:
1435 // `N2::f` is a qualified-id, so its terminal name 'f' undergoes (qualified) lookup.
1436 // Search in N2 performed by qualified lookup finds N1::f via using-declaration,
1437 // which is the (only) result of qualified lookup.
1438 // This friend declaration corresponds to the result of the lookup.
1439 // All lookup results target the same scope, which is N1,
1440 // so target scope of this friend declaration is also N1.
1441 // FIXME: This is well-formed.
1442 friend void N2::f();
1443 // expected-error@-1 {{cannot befriend target of using declaration}}
1444 // expected-note@#cwg386-ex2-N1-f {{target of using declaration}}
1445 // expected-note@#cwg386-ex2-using {{using declaration}}
1448 } // namespace example2
1449 } // namespace cwg386
1451 namespace cwg387 { // cwg387: 2.8
1452 namespace old {
1453 template<typename T> class number {
1454 number(int); // #cwg387-number-ctor
1455 friend number gcd(number &x, number &y) {}
1458 void g() {
1459 number<double> a(3);
1460 // expected-error@-1 {{calling a private constructor of class 'cwg387::old::number<double>'}}
1461 // expected-note@#cwg387-number-ctor {{implicitly declared private here}}
1462 number<double> b(4);
1463 // expected-error@-1 {{calling a private constructor of class 'cwg387::old::number<double>'}}
1464 // expected-note@#cwg387-number-ctor {{implicitly declared private here}}
1465 a = gcd(a, b);
1466 b = gcd(3, 4);
1467 // expected-error@-1 {{use of undeclared identifier 'gcd'}}
1471 namespace newer {
1472 template <typename T> class number {
1473 public:
1474 number(int);
1475 friend number gcd(number x, number y) { return 0; }
1478 void g() {
1479 number<double> a(3), b(4);
1480 a = gcd(a, b);
1481 b = gcd(3, 4);
1482 // expected-error@-1 {{use of undeclared identifier 'gcd'}}
1487 // FIXME: cwg388 needs libc++abi test
1489 namespace cwg389 { // cwg389: no
1490 struct S {
1491 typedef struct {} A;
1492 typedef enum {} B;
1493 typedef struct {} const C; // #cwg389-C
1494 typedef enum {} const D; // #cwg389-D
1496 template<typename> struct T {};
1498 struct WithLinkage1 {};
1499 enum WithLinkage2 {};
1500 typedef struct {} *WithLinkage3a, WithLinkage3b;
1501 typedef enum {} WithLinkage4a, *WithLinkage4b;
1502 typedef S::A WithLinkage5;
1503 typedef const S::B WithLinkage6;
1504 typedef int WithLinkage7;
1505 typedef void (*WithLinkage8)(WithLinkage2 WithLinkage1::*, WithLinkage5 *);
1506 typedef T<WithLinkage5> WithLinkage9;
1508 typedef struct {} *WithoutLinkage1; // #cwg389-no-link-1
1509 typedef enum {} const WithoutLinkage2; // #cwg389-no-link-2
1510 // These two types don't have linkage even though they are externally visible
1511 // and the ODR requires them to be merged across TUs.
1512 typedef S::C WithoutLinkage3;
1513 typedef S::D WithoutLinkage4;
1514 typedef void (*WithoutLinkage5)(int (WithoutLinkage3::*)(char));
1516 #if __cplusplus >= 201103L
1517 // This has linkage even though its template argument does not.
1518 // FIXME: This is probably a defect.
1519 typedef T<WithoutLinkage1> WithLinkage10;
1520 #else
1521 typedef int WithLinkage10; // dummy
1523 typedef T<WithLinkage1> GoodArg1;
1524 typedef T<WithLinkage2> GoodArg2;
1525 typedef T<WithLinkage3a> GoodArg3a;
1526 typedef T<WithLinkage3b> GoodArg3b;
1527 typedef T<WithLinkage4a> GoodArg4a;
1528 typedef T<WithLinkage4b> GoodArg4b;
1529 typedef T<WithLinkage5> GoodArg5;
1530 typedef T<WithLinkage6> GoodArg6;
1531 typedef T<WithLinkage7> GoodArg7;
1532 typedef T<WithLinkage8> GoodArg8;
1533 typedef T<WithLinkage9> GoodArg9;
1535 typedef T<WithoutLinkage1> BadArg1;
1536 // expected-error@-1 {{template argument uses unnamed type}}
1537 // expected-note@#cwg389-no-link-1 {{unnamed type used in template argument was declared here}}
1538 typedef T<WithoutLinkage2> BadArg2;
1539 // expected-error@-1 {{template argument uses unnamed type}}
1540 // expected-note@#cwg389-no-link-2 {{unnamed type used in template argument was declared here}}
1541 typedef T<WithoutLinkage3> BadArg3;
1542 // expected-error@-1 {{template argument uses unnamed type}}
1543 // expected-note@#cwg389-C {{unnamed type used in template argument was declared here}}
1544 typedef T<WithoutLinkage4> BadArg4;
1545 // expected-error@-1 {{template argument uses unnamed type}}
1546 // expected-note@#cwg389-D {{unnamed type used in template argument was declared here}}
1547 typedef T<WithoutLinkage5> BadArg5;
1548 // expected-error@-1 {{template argument uses unnamed type}}
1549 // expected-note@#cwg389-C {{unnamed type used in template argument was declared here}}
1550 #endif
1552 extern WithLinkage1 withLinkage1;
1553 extern WithLinkage2 withLinkage2;
1554 extern WithLinkage3a withLinkage3a;
1555 extern WithLinkage3b withLinkage3b;
1556 extern WithLinkage4a withLinkage4a;
1557 extern WithLinkage4b withLinkage4b;
1558 extern WithLinkage5 withLinkage5;
1559 extern WithLinkage6 withLinkage6;
1560 extern WithLinkage7 withLinkage7;
1561 extern WithLinkage8 withLinkage8;
1562 extern WithLinkage9 withLinkage9;
1563 extern WithLinkage10 withLinkage10;
1565 // FIXME: These are all ill-formed.
1566 extern WithoutLinkage1 withoutLinkage1;
1567 extern WithoutLinkage2 withoutLinkage2;
1568 extern WithoutLinkage3 withoutLinkage3;
1569 extern WithoutLinkage4 withoutLinkage4;
1570 extern WithoutLinkage5 withoutLinkage5;
1572 // OK, extern "C".
1573 extern "C" {
1574 extern WithoutLinkage1 cwg389_withoutLinkage1;
1575 extern WithoutLinkage2 cwg389_withoutLinkage2;
1576 extern WithoutLinkage3 cwg389_withoutLinkage3;
1577 extern WithoutLinkage4 cwg389_withoutLinkage4;
1578 extern WithoutLinkage5 cwg389_withoutLinkage5;
1581 // OK, defined.
1582 WithoutLinkage1 withoutLinkageDef1;
1583 WithoutLinkage2 withoutLinkageDef2 = WithoutLinkage2();
1584 WithoutLinkage3 withoutLinkageDef3 = {};
1585 WithoutLinkage4 withoutLinkageDef4 = WithoutLinkage4();
1586 WithoutLinkage5 withoutLinkageDef5;
1588 void use(const void *);
1589 void use_all() {
1590 use(&withLinkage1); use(&withLinkage2); use(&withLinkage3a); use(&withLinkage3b);
1591 use(&withLinkage4a); use(&withLinkage4b); use(&withLinkage5); use(&withLinkage6);
1592 use(&withLinkage7); use(&withLinkage8); use(&withLinkage9); use(&withLinkage10);
1594 use(&withoutLinkage1); use(&withoutLinkage2); use(&withoutLinkage3);
1595 use(&withoutLinkage4); use(&withoutLinkage5);
1597 use(&cwg389_withoutLinkage1); use(&cwg389_withoutLinkage2);
1598 use(&cwg389_withoutLinkage3); use(&cwg389_withoutLinkage4);
1599 use(&cwg389_withoutLinkage5);
1601 use(&withoutLinkageDef1); use(&withoutLinkageDef2); use(&withoutLinkageDef3);
1602 use(&withoutLinkageDef4); use(&withoutLinkageDef5);
1605 void local() {
1606 // FIXME: This is ill-formed.
1607 extern WithoutLinkage1 withoutLinkageLocal;
1611 namespace cwg390 { // cwg390: 3.3
1612 template<typename T>
1613 struct A {
1614 A() { f(); }
1615 // expected-warning@-1 {{call to pure virtual member function 'f' has undefined behavior; overrides of 'f' in subclasses are not available in the constructor of 'cwg390::A<int>'}}
1616 // expected-note@#cwg390-A-int {{in instantiation of member function 'cwg390::A<int>::A' requested here}}
1617 // expected-note@#cwg390-f {{'f' declared here}}
1618 virtual void f() = 0; // #cwg390-f
1619 virtual ~A() = 0;
1621 template<typename T> A<T>::~A() { T::error; }
1622 // expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}
1623 // expected-note@#cwg390-A-int {{in instantiation of member function 'cwg390::A<int>::~A' requested here}}
1624 template<typename T> void A<T>::f() { T::error; } // ok, not odr-used
1625 struct B : A<int> { // #cwg390-A-int
1626 void f() {}
1627 } b;
1630 namespace cwg391 { // cwg391: 2.8 c++11
1631 // FIXME: Should this apply to C++98 too?
1632 class A { A(const A&); }; // #cwg391-A
1633 A fa();
1634 const A &a = fa();
1635 // cxx98-error@-1 {{C++98 requires an accessible copy constructor for class 'cwg391::A' when binding a reference to a temporary; was private}}
1636 // cxx98-note@#cwg391-A {{implicitly declared private here}}
1638 struct B { B(const B&) = delete; }; // #cwg391-B
1639 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
1640 B fb();
1641 const B &b = fb();
1642 // cxx98-error@-1 {{copying variable of type 'B' invokes deleted constructor}}
1643 // cxx98-note@#cwg391-B {{'B' has been explicitly marked deleted here}}
1645 template<typename T>
1646 struct C {
1647 C(const C&) { T::error; }
1649 C<int> fc();
1650 const C<int> &c = fc();
1653 // cwg392 is in cwg392.cpp
1655 namespace cwg393 { // cwg393: 2.7
1656 template <typename T>
1657 struct S {};
1659 void f1(S<int (*)[]>);
1660 void f2(S<int (&)[]>);
1661 void g(int(*S<int>::*)[]);
1663 template<typename T>
1664 void sp_assert_convertible( T* ) {}
1666 template<typename T, typename U>
1667 void h() {
1668 T (*p) [] = (U(*)[])0;
1669 sp_assert_convertible<T[]>( (U(*)[])0 );
1671 } // namespace cwg393
1673 // cwg394: na
1675 namespace cwg395 { // cwg395: 3.0
1676 struct S {
1677 template <typename T, int N>(&operator T())[N];
1678 // expected-error@-1 {{cannot specify any part of a return type in the declaration of a conversion function}}
1679 template <typename T, int N> operator(T (&)[N])();
1680 // expected-error@-1 {{expected ')'}}
1681 // expected-note@-2 {{to match this '('}}
1682 // expected-error@-3 {{a type specifier is required for all declarations}}
1683 template <typename T> operator T *() const { return 0; }
1684 template <typename T, typename U> operator T U::*() const { return 0; }
1685 template <typename T, typename U> operator T (U::*)()() const { return 0; }
1686 // expected-error@-1 {{a type specifier is required for all declarations}}
1687 // expected-error@-2 {{conversion function cannot have any parameters}}
1688 // expected-error@-3 {{cannot specify any part of a return type in the declaration of a conversion function}}
1689 // expected-error@-4 {{conversion function cannot convert to a function type}}
1693 struct null1_t {
1694 template <class T, class U> struct ptr_mem_fun_t {
1695 typedef T (U::*type)();
1698 template <class T, class U>
1699 operator typename ptr_mem_fun_t<T, U>::type() const { // #cwg395-conv-func
1700 return 0;
1702 } null1;
1703 int (S::*p)() = null1;
1704 // expected-error@-1 {{no viable conversion from 'struct null1_t' to 'int (cwg395::S::*)()'}}
1705 // expected-note@#cwg395-conv-func {{candidate template ignored: couldn't infer template argument 'T'}}
1707 template <typename T> using id = T;
1708 // cxx98-error@-1 {{alias declarations are a C++11 extension}}
1710 struct T {
1711 template <typename T, int N> operator id<T[N]> &();
1712 template <typename T, typename U> operator id<T (U::*)()>() const;
1715 struct null2_t {
1716 template<class T, class U> using ptr_mem_fun_t = T (U::*)();
1717 // cxx98-error@-1 {{alias declarations are a C++11 extension}}
1718 template<class T, class U> operator ptr_mem_fun_t<T, U>() const { return 0; };
1719 } null2;
1720 int (S::*q)() = null2;
1723 namespace cwg396 { // cwg396: yes
1724 void f() {
1725 auto int a();
1726 // since-cxx11-error@-1 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}}
1727 // expected-error@-2 {{illegal storage class on function}}
1728 int (i); // #cwg396-i
1729 auto int (i);
1730 // since-cxx11-error@-1 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}}
1731 // expected-error@-2 {{redefinition of 'i'}}
1732 // expected-note@#cwg396-i {{previous definition is here}}
1736 // cwg397: sup 1823
1738 namespace cwg398 { // cwg398: yes
1739 namespace example1 {
1740 struct S {
1741 static int const I = 42;
1743 template <int N> struct X {};
1744 template <typename T> void f(X<T::I> *) {}
1745 template <typename T> void f(X<T::J> *) {}
1746 void foo() { f<S>(0); }
1749 namespace example2 {
1750 template <int I> struct X {};
1751 template <template <class T> class> struct Z {};
1752 template <class T> void f(typename T::Y *) {} // #cwg398-f
1753 template <class T> void g(X<T::N> *) {} // #cwg398-g
1754 template <class T> void h(Z<T::template TT> *) {} // #cwg398-h
1755 struct A {};
1756 struct B {
1757 int Y;
1759 struct C {
1760 typedef int N;
1762 struct D {
1763 typedef int TT;
1766 void test() {
1767 f<A>(0);
1768 // expected-error@-1 {{no matching function for call to 'f'}}
1769 // expected-note@#cwg398-f {{candidate template ignored: substitution failure [with T = A]: no type named 'Y' in 'cwg398::example2::A'}}
1770 f<B>(0);
1771 // expected-error@-1 {{no matching function for call to 'f'}}
1772 // expected-note@#cwg398-f {{candidate template ignored: substitution failure [with T = B]: typename specifier refers to non-type member 'Y' in 'cwg398::example2::B'}}
1773 g<C>(0);
1774 // expected-error@-1 {{no matching function for call to 'g'}}
1775 // expected-note@#cwg398-g {{candidate template ignored: substitution failure [with T = C]: missing 'typename' prior to dependent type name 'C::N'}}
1776 h<D>(0);
1777 // expected-error@-1 {{no matching function for call to 'h'}}
1778 // expected-note@#cwg398-h {{candidate template ignored: substitution failure [with T = D]: 'TT' following the 'template' keyword does not refer to a template}}
1783 namespace cwg399 { // cwg399: 11
1784 // NB: reuse cwg244 test
1785 struct B {}; // #cwg399-B
1786 struct D : B {};
1788 D D_object;
1789 typedef B B_alias;
1790 B* B_ptr = &D_object;
1792 void f() {
1793 D_object.~B();
1794 // expected-error@-1 {{destructor type 'cwg399::B' in object destruction expression does not match the type 'D' of the object being destroyed}}
1795 // expected-note@#cwg399-B {{type 'cwg399::B' found by destructor name lookup}}
1796 D_object.B::~B();
1797 D_object.D::~B(); // FIXME: Missing diagnostic for this.
1798 B_ptr->~B();
1799 B_ptr->~B_alias();
1800 B_ptr->B_alias::~B();
1801 B_ptr->B_alias::~B_alias();
1802 B_ptr->cwg399::~B();
1803 // expected-error@-1 {{no member named '~B' in namespace 'cwg399'}}
1804 B_ptr->cwg399::~B_alias();
1805 // expected-error@-1 {{no member named '~B' in namespace 'cwg399'}}
1808 template<typename T, typename U>
1809 void f(T *B_ptr, U D_object) {
1810 D_object.~B(); // FIXME: Missing diagnostic for this.
1811 D_object.B::~B();
1812 D_object.D::~B(); // FIXME: Missing diagnostic for this.
1813 B_ptr->~B();
1814 B_ptr->~B_alias();
1815 B_ptr->B_alias::~B();
1816 B_ptr->B_alias::~B_alias();
1817 B_ptr->cwg399::~B();
1818 // expected-error@-1 {{'cwg399' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
1819 B_ptr->cwg399::~B_alias();
1820 // expected-error@-1 {{'cwg399' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
1822 template void f<B, D>(B*, D);
1824 namespace N {
1825 template<typename T> struct E {};
1826 typedef E<int> F;
1828 void g(N::F f) {
1829 typedef N::F G; // #cwg399-G
1830 f.~G();
1831 f.G::~E();
1832 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
1833 f.G::~F();
1834 // expected-error@-1 {{undeclared identifier 'F' in destructor name}}
1835 f.G::~G();
1836 // This is technically ill-formed; E is looked up in 'N::' and names the
1837 // class template, not the injected-class-name of the class. But that's
1838 // probably a bug in the standard.
1839 f.N::F::~E();
1840 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
1841 // This is valid; we look up the second F in the same scope in which we
1842 // found the first one, that is, 'N::'.
1843 f.N::F::~F();
1844 // This is technically ill-formed; G is looked up in 'N::' and is not found.
1845 // Rejecting this seems correct, but most compilers accept, so we do also.
1846 f.N::F::~G();
1847 // expected-error@-1 {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}
1848 // expected-note@#cwg399-G {{type 'G' (aka 'E<int>') found by destructor name lookup}}
1851 // Bizarrely, compilers perform lookup in the scope for qualified destructor
1852 // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
1853 // this.
1854 namespace QualifiedLookupInScope {
1855 namespace N {
1856 template <typename> struct S { struct Inner {}; };
1858 template <typename U> void f(typename N::S<U>::Inner *p) {
1859 typedef typename N::S<U>::Inner T;
1860 p->::cwg399::QualifiedLookupInScope::N::S<U>::Inner::~T();
1861 // expected-error@-1 {{no type named 'T' in 'cwg399::QualifiedLookupInScope::N::S<int>'}}
1862 // expected-note@#cwg399-f {{in instantiation of function template specialization 'cwg399::QualifiedLookupInScope::f<int>' requested here}}
1864 template void f<int>(N::S<int>::Inner *); // #cwg399-f
1866 template <typename U> void g(U *p) {
1867 typedef U T;
1868 p->T::~T();
1869 p->U::~T();
1870 p->::cwg399::QualifiedLookupInScope::N::S<int>::Inner::~T();
1871 // expected-error@-1 {{'T' does not refer to a type name in pseudo-destructor expression; expected the name of type 'U'}}
1873 template void g(N::S<int>::Inner *);