Debian Codegraph @

clang/test/CXX/drs/cwg3xx.cpp

raw
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
7
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
12
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
18
19 namespace cwg300 { // cwg300: yes
20 template<typename R, typename A> void f(R (&)(A)) {}
21 int g(int);
22 void h() { f(g); }
23 }
24
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);
30
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 '<'}}
41 }
42
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
63 }
64
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}}
78 }
79
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
111 }
112
113 // cwg303: na
114
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}}
119
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}}
126 }
127
128 namespace cwg305 { // cwg305: no
129 struct A {
130 typedef A C;
131 };
132 void f(A *a) {
133 struct A {};
134 a->~A();
135 a->~C();
136 }
137 typedef A B;
138 void g(B *b) {
139 b->~B();
140 b->~C();
141 }
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}}
147 }
148
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>'}}
156 }
157
158 #if __cplusplus >= 201103L
159 struct Y {
160 template<typename T> using T1 = Y;
161 };
162 template<typename T> using T2 = Y;
163 void j(Y *y) {
164 y->~T1<int>();
165 y->~T2<int>();
166 }
167 struct Z {
168 template<typename T> using T2 = T;
169 };
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>();
176 }
177
178 // FIXME: This is valid.
179 namespace Q {
180 template<typename A> struct R {};
181 }
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
186 }
187
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;
193
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}}
202 }
203
204 // cwg307: na
205
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
230 }
231 }
232 }
233
234 // cwg309: dup 485
235
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}}
243 }
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}}
250 }
251
252 // cwg312: dup 616
253
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}}
259 }
260
261 namespace cwg314 { // cwg314: no
262 // NB: dup 1710
263 template <typename T> struct A {
264 template <typename U> struct B {};
265 };
266 template <typename T> struct C : public A<T>::template B<T> {
267 C() : A<T>::template B<T>() {}
268 };
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}}
273 };
274 } // namespace cwg314
275
276 // cwg315: na
277 // cwg316: sup 1004
278
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}}
284
285 int g();
286 int n = g();
287 inline int g() { return 0; }
288
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}}
295 }
296
297 namespace cwg318 { // cwg318: sup 1310
298 struct A {};
299 struct A::A a;
300 }
301
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
311
312 static enum { e } a1;
313 enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage
314
315 enum { n1 = 1u };
316 typedef int (*pa)[n1];
317 pa parr; // ok, type has linkage despite using 'n1'
318
319 template<typename> struct X {};
320
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'}}
326
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'}}
331
332 const int n = 1;
333 typedef int (*C)[n];
334 extern C c; // ok
335 X<C> xc;
336 }
337 }
338
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;
345 };
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
350 }
351
352 namespace cwg321 { // cwg321: dup 557
353 namespace N {
354 template<int> struct A {
355 template<int> struct B;
356 };
357 template<> template<> struct A<0>::B<0>;
358 void f(A<0>::B<0>);
359 }
360 template<> template<> struct N::A<0>::B<0> {};
361
362 template<typename T> void g(T t) { f(t); }
363 template void g(N::A<0>::B<0>);
364
365 namespace N {
366 template<typename> struct I { friend bool operator==(const I&, const I&); };
367 }
368 N::I<int> i, j;
369 bool x = i == j;
370 }
371
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;
378 }
379
380 // cwg323: sup 820
381
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}}
406 }
407
408 namespace cwg326 { // cwg326: 3.1
409 struct S {};
410 static_assert(__is_trivially_constructible(S, const S&), "");
411 }
412
413 namespace cwg327 { // cwg327: dup 538
414 struct A;
415 class A {};
416
417 class B;
418 struct B {};
419 }
420
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'}}
432 }
433
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}}
445 };
446 A<int> a;
447 A<char> b; // #cwg329-b
448
449 void test() {
450 h(a); // #cwg329-h-call
451 }
452 }
453
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}}
501
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);
521 }
522
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);
529 }
530
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);
544 }
545 }
546 }
547
548 namespace cwg331 { // cwg331: 11
549 struct A {
550 A(volatile A&); // #cwg331-A-ctor
551 };
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}}
558 }
559
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}}
569 }
570
571 namespace cwg333 { // cwg333: yes
572 int n = 0;
573 int f(int(n));
574 int g((int(n)));
575 int h = f(g);
576 }
577
578 namespace cwg334 { // cwg334: yes
579 template<typename T> void f() {
580 T x;
581 f((x, 123));
582 }
583 struct S {
584 friend S operator,(S, int);
585 friend void f(S);
586 };
587 template void f<S>();
588 }
589
590 // cwg335: sup 820
591
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();
598 };
599 };
600 template<> template<class X> class A<int>::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 template<class Y> template<> void A<Y>::B<double>::mf2() {}
604 // 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}}
605 }
606 namespace Post {
607 template<class T1> class A {
608 template<class T2> class B {
609 template<class T3> void mf1(T3);
610 void mf2();
611 };
612 };
613 template<> template<class X> class A<int>::B {
614 template<class T> void mf1(T);
615 };
616 template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {}
617 // FIXME: This diagnostic isn't very good.
618 template<class Y> template<> void A<Y>::B<double>::mf2() {}
619 // 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}}
620 }
621 }
622
623 namespace cwg337 { // cwg337: yes
624 template<typename T> void f(T (*)[1]);
625 template<typename T> int &f(...);
626
627 struct A { virtual ~A() = 0; };
628 int &r = f<A>(0);
629
630 // FIXME: The language rules here are completely broken. We cannot determine
631 // whether an incomplete type is abstract. See CWG1640, which will probably
632 // supersede this one and remove this rule.
633 struct B;
634 int &s = f<B>(0);
635 // expected-error@-1 {{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'void'}}
636 struct B { virtual ~B() = 0; };
637 }
638
639 namespace cwg339 { // cwg339: 2.8
640 template <int I> struct A { static const int value = I; };
641
642 char xxx(int);
643 char (&xxx(float))[2];
644
645 template<class T> A<sizeof(xxx((T)0))> f(T) {} // #cwg339-f
646
647 void test() {
648 A<1> a = f(0);
649 A<2> b = f(0.0f);
650 A<3> c = f("foo");
651 // expected-error@-1 {{no matching function}}
652 // expected-note@#cwg339-f {{candidate}}
653 }
654
655
656 char f(int);
657 int f(...);
658
659 template <class T> struct conv_int {
660 static const bool value = sizeof(f(T())) == 1;
661 };
662
663 template <class T> bool conv_int2(A<sizeof(f(T()))> p);
664
665 template<typename T> A<sizeof(f(T()))> make_A();
666
667 static_assert(conv_int<char>::value, "");
668 bool b = conv_int2<char>(A<1>());
669 A<1> c = make_A<char>();
670 }
671
672 namespace cwg340 { // cwg340: yes
673 struct A { A(int); };
674 struct B { B(A, A, int); };
675 int x, y;
676 B b(A(x), A(y), 3);
677 }
678
679 namespace cwg341 { // cwg341: sup 1708
680 namespace A {
681 int n;
682 extern "C" int &cwg341_a = n; // #cwg341_a
683 }
684 namespace B {
685 extern "C" int &cwg341_a = cwg341_a;
686 // expected-error@-1 {{redefinition of 'cwg341_a'}}
687 // expected-note@#cwg341_a {{previous definition is here}}
688 }
689 extern "C" void cwg341_b(); // #cwg341_b
690 }
691 int cwg341_a;
692 // expected-error@-1 {{declaration of 'cwg341_a' in global scope conflicts with declaration with C language linkage}}
693 // expected-note@#cwg341_a {{declared with C language linkage here}}
694 int cwg341_b;
695 // expected-error@-1 {{declaration of 'cwg341_b' in global scope conflicts with declaration with C language linkage}}
696 // expected-note@#cwg341_b {{declared with C language linkage here}}
697 int cwg341_c; // #cwg341_c
698 int cwg341_d; // #cwg341_d
699 namespace cwg341 {
700 extern "C" int cwg341_c;
701 // expected-error@-1 {{declaration of 'cwg341_c' with C language linkage conflicts with declaration in global scope}}
702 // expected-note@#cwg341_c {{declared in global scope here}}
703 extern "C" void cwg341_d();
704 // expected-error@-1 {{declaration of 'cwg341_d' with C language linkage conflicts with declaration in global scope}}
705 // expected-note@#cwg341_d {{declared in global scope here}}
706
707 namespace A { extern "C" int cwg341_e; } // #cwg341_e
708 namespace B { extern "C" void cwg341_e(); }
709 // expected-error@-1 {{redefinition of 'cwg341_e' as different kind of symbol}}
710 // expected-note@#cwg341_e {{previous definition is here}}
711 }
712
713 // cwg342: na
714
715 namespace cwg343 { // cwg343: no
716 // FIXME: dup 1710
717 template<typename T> struct A {
718 template<typename U> struct B {};
719 };
720 // FIXME: In these contexts, the 'template' keyword is optional.
721 template<typename T> struct C : public A<T>::B<T> {
722 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
723 C() : A<T>::B<T>() {}
724 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
725 };
726 }
727
728 namespace cwg344 { // cwg344: dup 1435
729 struct A { inline virtual ~A(); };
730 struct B { friend A::~A(); };
731 }
732
733 namespace cwg345 { // cwg345: yes
734 struct A {
735 struct X {};
736 int X; // #cwg345-int-X
737 };
738 struct B {
739 struct X {};
740 };
741 template <class T> void f(T t) { typename T::X x; }
742 // expected-error@-1 {{typename specifier refers to non-type member 'X' in 'cwg345::A'}}
743 // expected-note@#cwg345-f-a {{in instantiation of function template specialization 'cwg345::f<cwg345::A>' requested here}}
744 // expected-note@#cwg345-int-X {{referenced member 'X' is declared here}}
745 void f(A a, B b) {
746 f(b);
747 f(a); // #cwg345-f-a
748 }
749 }
750
751 // cwg346: na
752
753 namespace cwg347 { // cwg347: yes
754 struct base {
755 struct nested;
756 static int n;
757 static void f();
758 void g();
759 };
760
761 struct derived : base {};
762
763 struct derived::nested {};
764 // expected-error@-1 {{no struct named 'nested' in 'cwg347::derived'}}
765 int derived::n;
766 // expected-error@-1 {{no member named 'n' in 'cwg347::derived'}}
767 void derived::f() {}
768 // expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'cwg347::derived'}}
769 void derived::g() {}
770 // expected-error@-1 {{out-of-line definition of 'g' does not match any declaration in 'cwg347::derived'}}
771 }
772
773 // cwg348: na
774
775 namespace cwg349 { // cwg349: no
776 struct A {
777 template <class T> operator T ***() {
778 int ***p = 0;
779 return p;
780 // cxx98-20-error@-1 {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}}
781 // since-cxx23-error@-2 {{cannot initialize return object of type 'const int ***' with an rvalue of type 'int ***'}}
782 // expected-note@#cwg349-p1 {{in instantiation of function template specialization 'cwg349::A::operator const int ***<const int>' requested here}}
783 }
784 };
785
786 // FIXME: This is valid.
787 A a;
788 const int *const *const *p1 = a; // #cwg349-p1
789
790 struct B {
791 template <class T> operator T ***() {
792 const int ***p = 0;
793 return p;
794 }
795 };
796
797 // FIXME: This is invalid.
798 B b;
799 const int *const *const *p2 = b;
800 }
801
802 // cwg351: na
803
804 namespace cwg352 { // cwg352: 2.8
805 namespace example1 {
806 namespace A {
807 enum E {};
808 template<typename R, typename A> void foo(E, R (*)(A)); // #cwg352-foo
809 }
810
811 template<typename T> void arg(T);
812 template<typename T> int arg(T) = delete; // #cwg352-deleted
813 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
814
815 void f(A::E e) {
816 foo(e, &arg);
817 // expected-error@-1 {{no matching function for call to 'foo'}}
818 // expected-note@#cwg352-foo {{candidate template ignored: couldn't infer template argument 'R'}}
819
820 using A::foo;
821 foo<int, int>(e, &arg);
822 // expected-error@-1 {{attempt to use a deleted function}}
823 // expected-note@#cwg352-deleted {{'arg<int>' has been explicitly marked deleted here}}
824 }
825
826 int arg(int);
827
828 void g(A::E e) {
829 foo(e, &arg);
830 // expected-error@-1 {{no matching function for call to 'foo'}}
831 // expected-note@#cwg352-foo {{candidate template ignored: couldn't infer template argument 'R'}}
832
833 using A::foo;
834 foo<int, int>(e, &arg); // ok, uses non-template
835 }
836 }
837
838 namespace contexts {
839 template<int I> void f1(int (&)[I]);
840 template<int I> void f2(int (&)[I+1]); // #cwg352-f2
841 template<int I> void f3(int (&)[I+1], int (&)[I]);
842 void f() {
843 int a[4];
844 int b[3];
845 f1(a);
846 f2(a);
847 // expected-error@-1 {{no matching function for call to 'f2'}}
848 // expected-note@#cwg352-f2 {{candidate template ignored: couldn't infer template argument 'I'}}
849 f3(a, b);
850 }
851
852 template<int I> struct S {};
853 template<int I> void g1(S<I>);
854 template<int I> void g2(S<I+1>); // #cwg352-g2
855 template<int I> void g3(S<I+1>, S<I>);
856 void g() {
857 S<4> a;
858 S<3> b;
859 g1(a);
860 g2(a);
861 // expected-error@-1 {{no matching function for call to 'g2'}}
862 // expected-note@#cwg352-g2 {{candidate template ignored: couldn't infer template argument 'I'}}
863 g3(a, b);
864 }
865
866 template<typename T> void h1(T = 0); // #cwg352-h1
867 template<typename T> void h2(T, T = 0);
868 void h() {
869 h1();
870 // expected-error@-1 {{no matching function for call to 'h1'}}
871 // expected-note@#cwg352-h1 {{candidate template ignored: couldn't infer template argument 'T'}}
872 h1(0);
873 h1<int>();
874 h2(0);
875 }
876
877 template<typename T> int tmpl(T);
878 template<typename R, typename A> void i1(R (*)(A)); // #cwg352-i1
879 template<typename R, typename A> void i2(R, A, R (*)(A)); // #cwg352-i2
880 void i() {
881 extern int single(int);
882 i1(single);
883 i2(0, 0, single);
884
885 extern int ambig(float), ambig(int);
886 i1(ambig);
887 // expected-error@-1 {{no matching function for call to 'i1'}}
888 // expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}}
889 i2(0, 0, ambig);
890
891 extern void no_match(float), no_match(int);
892 i1(no_match);
893 // expected-error@-1 {{no matching function for call to 'i1'}}
894 // expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}}
895 i2(0, 0, no_match);
896 // expected-error@-1 {{no matching function for call to 'i2'}}
897 // expected-note@#cwg352-i2 {{candidate function [with R = int, A = int] not viable: no overload of 'no_match' matching 'int (*)(int)' for 3rd argument}}
898
899 i1(tmpl);
900 // expected-error@-1 {{no matching function for call to 'i1'}}
901 // expected-note@#cwg352-i1 {{candidate template ignored: couldn't infer template argument 'R'}}
902 i2(0, 0, tmpl);
903 }
904 }
905
906 template<typename T> struct is_int;
907 template<> struct is_int<int> {};
908
909 namespace example2 {
910 template<typename T> int f(T (*p)(T)) { is_int<T>(); }
911 int g(int);
912 int g(char);
913 int i = f(g);
914 }
915
916 namespace example3 {
917 template<typename T> int f(T, T (*p)(T)) { is_int<T>(); }
918 int g(int);
919 char g(char);
920 int i = f(1, g);
921 }
922
923 namespace example4 {
924 template <class T> int f(T, T (*p)(T)) { is_int<T>(); }
925 char g(char);
926 template <class T> T g(T);
927 int i = f(1, g);
928 }
929
930 namespace example5 {
931 template<int I> class A {};
932 template<int I> void g(A<I+1>); // #cwg352-g
933 template<int I> void f(A<I>, A<I+1>);
934 void h(A<1> a1, A<2> a2) {
935 g(a1);
936 // expected-error@-1 {{no matching function for call to 'g'}}
937 // expected-note@#cwg352-g {{candidate template ignored: couldn't infer template argument 'I'}}
938 g<0>(a1);
939 f(a1, a2);
940 }
941 }
942 }
943
944 // cwg353 needs an IRGen test.
945
946 namespace cwg354 { // cwg354: yes c++11
947 // FIXME: Should we allow this in C++98 too?
948 struct S {};
949
950 template<int*> struct ptr {}; // #cwg354-ptr
951 ptr<0> p0; // #cwg354-p0
952 // cxx98-error@#cwg354-p0 {{non-type template argument does not refer to any declaration}}
953 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
954 // cxx11-14-error@#cwg354-p0 {{null non-type template argument must be cast to template parameter type 'int *'}}
955 // cxx11-14-note@#cwg354-ptr {{template parameter is declared here}}
956 // since-cxx17-error@#cwg354-p0 {{conversion from 'int' to 'int *' is not allowed in a converted constant expression}}
957 ptr<(int*)0> p1;
958 // cxx98-error@-1 {{non-type template argument does not refer to any declaration}}
959 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
960 ptr<(float*)0> p2; // #cwg354-p2
961 // cxx98-error@#cwg354-p2 {{non-type template argument does not refer to any declaration}}
962 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
963 // cxx11-14-error@#cwg354-p2 {{null non-type template argument of type 'float *' does not match template parameter of type 'int *'}}
964 // cxx11-14-note@#cwg354-ptr {{template parameter is declared here}}
965 // since-cxx17-error@#cwg354-p2 {{value of type 'float *' is not implicitly convertible to 'int *'}}
966 ptr<(int S::*)0> p3; // #cwg354-p3
967 // cxx98-error@#cwg354-p3 {{non-type template argument does not refer to any declaration}}
968 // cxx98-note@#cwg354-ptr {{template parameter is declared here}}
969 // cxx11-14-error@#cwg354-p3 {{null non-type template argument of type 'int cwg354::S::*' does not match template parameter of type 'int *'}}
970 // cxx11-14-note@#cwg354-ptr {{template parameter is declared here}}
971 // since-cxx17-error@#cwg354-p3 {{value of type 'int cwg354::S::*' is not implicitly convertible to 'int *'}}
972
973 template<int*> int both(); // #cwg354-both-int-ptr
974 template<int> int both(); // #cwg354-both-int
975 int b0 = both<0>();
976 int b1 = both<(int*)0>();
977 // cxx98-error@-1 {{no matching function for call to 'both'}}
978 // cxx98-note@#cwg354-both-int-ptr {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
979 // cxx98-note@#cwg354-both-int {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
980
981 template<int S::*> struct ptr_mem {}; // #cwg354-ptr_mem
982 ptr_mem<0> m0; // #cwg354-m0
983 // cxx98-error@#cwg354-m0 {{non-type template argument of type 'int' cannot be converted to a value of type 'int cwg354::S::*'}}
984 // cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}}
985 // cxx11-14-error@#cwg354-m0 {{null non-type template argument must be cast to template parameter type 'int cwg354::S::*'}}
986 // cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}}
987 // since-cxx17-error@#cwg354-m0 {{conversion from 'int' to 'int cwg354::S::*' is not allowed in a converted constant expression}}
988 ptr_mem<(int S::*)0> m1;
989 // cxx98-error@-1 {{non-type template argument is not a pointer to member constant}}
990 ptr_mem<(float S::*)0> m2; // #cwg354-m2
991 // cxx98-error@#cwg354-m2 {{non-type template argument of type 'float cwg354::S::*' cannot be converted to a value of type 'int cwg354::S::*'}}
992 // cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}}
993 // 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::*'}}
994 // cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}}
995 // since-cxx17-error@#cwg354-m2 {{value of type 'float cwg354::S::*' is not implicitly convertible to 'int cwg354::S::*'}}
996 ptr_mem<(int *)0> m3; // #cwg354-m3
997 // cxx98-error@#cwg354-m3 {{non-type template argument of type 'int *' cannot be converted to a value of type 'int cwg354::S::*'}}
998 // cxx98-note@#cwg354-ptr_mem {{template parameter is declared here}}
999 // cxx11-14-error@#cwg354-m3 {{null non-type template argument of type 'int *' does not match template parameter of type 'int cwg354::S::*'}}
1000 // cxx11-14-note@#cwg354-ptr_mem {{template parameter is declared here}}
1001 // since-cxx17-error@#cwg354-m3 {{value of type 'int *' is not implicitly convertible to 'int cwg354::S::*'}}
1002 }
1003
1004 struct cwg355_S; // cwg355: yes
1005 struct ::cwg355_S {};
1006 // expected-warning@-1 {{extra qualification on member 'cwg355_S'}}
1007 namespace cwg355 { struct ::cwg355_S s; }
1008
1009 // cwg356: na
1010
1011 namespace cwg357 { // cwg357: yes
1012 template<typename T> struct A {
1013 void f() const; // #cwg357-f
1014 };
1015 template<typename T> void A<T>::f() {}
1016 // expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'A<T>'}}
1017 // expected-note@#cwg357-f {{member declaration does not match because it is const qualified}}
1018
1019 struct B {
1020 template<typename T> void f();
1021 };
1022 template<typename T> void B::f() const {}
1023 // expected-error@-1 {{out-of-line definition of 'f' does not match any declaration in 'cwg357::B'}}
1024 }
1025
1026 namespace cwg358 { // cwg358: yes
1027 extern "C" void cwg358_f();
1028 namespace N {
1029 int var;
1030 extern "C" void cwg358_f() { var = 10; }
1031 }
1032 }
1033
1034 namespace cwg359 { // cwg359: yes
1035 // Note, the example in the DR is wrong; it doesn't contain an anonymous
1036 // union.
1037 struct E {
1038 union {
1039 struct {
1040 int x;
1041 } s;
1042 } v;
1043
1044 union {
1045 struct {
1046 // expected-error@-1 {{anonymous types declared in an anonymous union are an extension}}
1047 int x;
1048 } s;
1049
1050 struct S {
1051 // expected-error@-1 {{types cannot be declared in an anonymous union}}
1052 int x;
1053 } t;
1054
1055 union {
1056 // expected-error@-1 {{anonymous types declared in an anonymous union are an extension}}
1057 int u;
1058 };
1059 };
1060 };
1061 }
1062
1063 namespace cwg360 { // cwg360: yes
1064 struct A {
1065 int foo();
1066 int bar();
1067
1068 protected:
1069 int baz();
1070 };
1071
1072 struct B : A {
1073 private:
1074 using A::foo; // #cwg360-using-foo
1075 protected:
1076 using A::bar; // #cwg360-using-bar
1077 public:
1078 using A::baz;
1079 };
1080
1081 int main() {
1082 int foo = B().foo();
1083 // expected-error@-1 {{'foo' is a private member of 'cwg360::B'}}
1084 // expected-note@#cwg360-using-foo {{declared private here}}
1085 int bar = B().bar();
1086 // expected-error@-1 {{'bar' is a protected member of 'cwg360::B'}}
1087 // expected-note@#cwg360-using-bar {{declared protected here}}
1088 int baz = B().baz();
1089 }
1090 } // namespace cwg360
1091
1092 // cwg362: na
1093 // cwg363: na
1094
1095 namespace cwg364 { // cwg364: yes
1096 struct S {
1097 static void f(int);
1098 void f(char);
1099 };
1100
1101 void g() {
1102 S::f('a');
1103 // expected-error@-1 {{call to non-static member function without an object argument}}
1104 S::f(0);
1105 }
1106 }
1107
1108 // cwg366: yes
1109 #if "foo" // expected-error {{invalid token at start of a preprocessor expression}}
1110 #endif
1111
1112 namespace cwg367 { // cwg367: yes
1113 static_assert(__enable_constant_folding(true ? throw 0 : 4), "");
1114 // expected-error@-1 {{expression is not an integral constant expression}}
1115 static_assert(__enable_constant_folding(true ? 4 : throw 0), "");
1116 static_assert(__enable_constant_folding(true ? *new int : 4), "");
1117 // expected-error@-1 {{expression is not an integral constant expression}}
1118 // expected-note@-2 {{read of uninitialized object is not allowed in a constant expression}}
1119 static_assert(__enable_constant_folding(true ? 4 : *new int), "");
1120
1121 }
1122
1123 namespace cwg368 { // cwg368: 3.6
1124 template<typename T, T> struct S {}; // #cwg368-S
1125 template<typename T> int f(S<T, T()> *);
1126 // expected-error@-1 {{template argument for non-type template parameter is treated as function type 'T ()'}}
1127 // expected-note@#cwg368-S {{template parameter is declared here}}
1128 template<typename T> int g(S<T, (T())> *); // #cwg368-g
1129 template<typename T> int g(S<T, true ? T() : T()> *); // #cwg368-g-2
1130 struct X {};
1131 int n = g<X>(0); // #cwg368-g-call
1132 // cxx98-17-error@#cwg368-g-call {{no matching function for call to 'g'}}
1133 // 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}}
1134 // 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}}
1135 // cxx20-23-error@#cwg368-g-call {{call to 'g' is ambiguous}}
1136 // cxx20-23-note@#cwg368-g {{candidate function [with T = cwg368::X]}}
1137 // cxx20-23-note@#cwg368-g-2 {{candidate function [with T = cwg368::X]}}
1138 }
1139
1140 // cwg370: na
1141
1142 namespace cwg372 { // cwg372: no
1143 namespace example1 {
1144 template<typename T> struct X {
1145 protected:
1146 typedef T Type; // #cwg372-ex1-Type
1147 };
1148 template<typename T> struct Y {};
1149
1150 // FIXME: These two are valid; deriving from T1<T> gives Z1 access to
1151 // the protected member T1<T>::Type.
1152 template<typename T,
1153 template<typename> class T1,
1154 template<typename> class T2> struct Z1 :
1155 T1<T>,
1156 T2<typename T1<T>::Type> {};
1157 // expected-error@-1 {{'Type' is a protected member of 'cwg372::example1::X<int>'}}
1158 // expected-note@#cwg372-z1 {{in instantiation of template class 'cwg372::example1::Z1<int, cwg372::example1::X, cwg372::example1::Y>' requested here}}
1159 // expected-note@#cwg372-ex1-Type {{declared protected here}}
1160
1161 template<typename T,
1162 template<typename> class T1,
1163 template<typename> class T2> struct Z2 :
1164 T2<typename T1<T>::Type>,
1165 // expected-error@-1 {{'Type' is a protected member of 'cwg372::example1::X<int>'}}
1166 // expected-note@#cwg372-z2 {{in instantiation of template class 'cwg372::example1::Z2<int, cwg372::example1::X, cwg372::example1::Y>' requested here}}
1167 // expected-note@#cwg372-ex1-Type {{declared protected here}}
1168 T1<T> {};
1169
1170 Z1<int, X, Y> z1; // #cwg372-z1
1171 Z2<int, X, Y> z2; // #cwg372-z2
1172 }
1173
1174 namespace example2 {
1175 struct X {
1176 private:
1177 typedef int Type; // #cwg372-ex2-Type
1178 };
1179 template<typename T> struct A {
1180 typename T::Type t;
1181 // expected-error@-1 {{'Type' is a private member of 'cwg372::example2::X'}}
1182 // expected-note@#cwg372-ax {{in instantiation of template class 'cwg372::example2::A<cwg372::example2::X>' requested here}}
1183 // expected-note@#cwg372-ex2-Type {{declared private here}}
1184 };
1185 A<X> ax; // #cwg372-ax
1186 }
1187
1188 namespace example3 {
1189 struct A {
1190 protected:
1191 typedef int N; // #cwg372-N
1192 };
1193
1194 template<typename T> struct B {};
1195 template<typename U> struct C : U, B<typename U::N> {};
1196 // expected-error@-1 {{'N' is a protected member of 'cwg372::example3::A'}}
1197 // expected-note@#cwg372-x {{in instantiation of template class 'cwg372::example3::C<cwg372::example3::A>' requested here}}
1198 // expected-note@#cwg372-N {{declared protected here}}
1199 template<typename U> struct D : B<typename U::N>, U {};
1200 // expected-error@-1 {{'N' is a protected member of 'cwg372::example3::A'}}
1201 // expected-note@#cwg372-y {{in instantiation of template class 'cwg372::example3::D<cwg372::example3::A>' requested here}}
1202 // expected-note@#cwg372-N {{declared protected here}}
1203
1204 C<A> x; // #cwg372-x
1205 D<A> y; // #cwg372-y
1206 }
1207
1208 namespace example4 {
1209 class A {
1210 class B {};
1211 friend class X;
1212 };
1213
1214 struct X : A::B {
1215 A::B mx;
1216 class Y {
1217 A::B my;
1218 };
1219 };
1220 }
1221
1222 // FIXME: This is valid: deriving from A gives D access to A::B
1223 namespace std_example {
1224 class A {
1225 protected:
1226 struct B {}; // #cwg372-B-std
1227 };
1228 struct D : A::B, A {};
1229 // expected-error@-1 {{'B' is a protected member of 'cwg372::std_example::A'}}
1230 // expected-note@#cwg372-B-std {{declared protected here}}
1231 }
1232
1233 // FIXME: This is valid: deriving from A::B gives access to A::B!
1234 namespace badwolf {
1235 class A {
1236 protected:
1237 struct B; // #cwg372-B
1238 };
1239 struct A::B : A {};
1240 struct C : A::B {};
1241 // expected-error@-1 {{'B' is a protected member of 'cwg372::badwolf::A'}}
1242 // expected-note@#cwg372-B {{declared protected here}}
1243 }
1244 }
1245
1246 namespace cwg373 { // cwg373: 5
1247 namespace X { int cwg373; }
1248 struct cwg373 { // #cwg373-struct
1249 void f() {
1250 using namespace cwg373::X;
1251 int k = cwg373;
1252 // expected-error@-1 {{'cwg373' does not refer to a value}}
1253 // expected-note@#cwg373-struct {{declared here}}
1254 namespace Y = cwg373::X;
1255 k = Y::cwg373;
1256 }
1257 };
1258
1259 struct A { struct B {}; }; // #cwg373-A
1260 namespace X = A::B;
1261 // expected-error@-1 {{expected namespace name}}
1262 // expected-note@#cwg373-A {{'A' declared here}}
1263 using namespace A::B;
1264 // expected-error@-1 {{expected namespace name}}
1265 // expected-note@#cwg373-A {{'A' declared here}}
1266 }
1267
1268 namespace cwg374 { // cwg374: 7
1269 // NB 2.9 c++11
1270 namespace N {
1271 template<typename T> void f();
1272 template<typename T> struct A { void f(); };
1273 }
1274 template<> void N::f<char>() {}
1275 template<> void N::A<char>::f() {}
1276 template<> struct N::A<int> {};
1277 }
1278
1279 // cwg375: dup 345
1280 // cwg376: na
1281
1282 namespace cwg377 { // cwg377: yes
1283 enum E {
1284 // expected-error@-1 {{enumeration values exceed range of largest integer}}
1285 a = -__LONG_LONG_MAX__ - 1,
1286 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1287 b = 2 * (unsigned long long)__LONG_LONG_MAX__
1288 // cxx98-error@-1 {{'long long' is a C++11 extension}}
1289 // cxx98-error@-2 {{'long long' is a C++11 extension}}
1290 };
1291 }
1292
1293 // cwg378: dup 276
1294 // cwg379: na
1295
1296 namespace cwg381 { // cwg381: yes
1297 struct A {
1298 int a;
1299 };
1300 struct B : virtual A {};
1301 struct C : B {};
1302 struct D : B {};
1303 struct E : public C, public D {};
1304 struct F : public A {};
1305 void f() {
1306 E e;
1307 e.B::a = 0;
1308 /* expected-error@-1 {{ambiguous conversion from derived class 'E' to base class 'cwg381::B':
1309 struct cwg381::E -> C -> B
1310 struct cwg381::E -> D -> B}} */
1311 F f;
1312 f.A::a = 1;
1313 }
1314 }
1315
1316 namespace cwg382 { // cwg382: yes c++11
1317 // FIXME: Should we allow this in C++98 mode?
1318 struct A { typedef int T; };
1319 typename A::T t;
1320 // cxx98-error@-1 {{'typename' occurs outside of a template}}
1321 typename cwg382::A a;
1322 // cxx98-error@-1 {{'typename' occurs outside of a template}}
1323 typename A b;
1324 // expected-error@-1 {{expected a qualified name after 'typename'}}
1325 }
1326
1327 namespace cwg383 { // cwg383: yes
1328 struct A { A &operator=(const A&); };
1329 struct B { ~B(); };
1330 union C { C &operator=(const C&); };
1331 union D { ~D(); };
1332 static_assert(!__is_pod(A) && !__is_pod(B) && !__is_pod(C) && !__is_pod(D), "");
1333 }
1334
1335 namespace cwg384 { // cwg384: yes
1336 namespace N1 {
1337 template<typename T> struct Base {};
1338 template<typename T> struct X {
1339 struct Y : public Base<T> {
1340 Y operator+(int) const;
1341 };
1342 Y f(unsigned i) { return Y() + i; }
1343 };
1344 }
1345
1346 namespace N2 {
1347 struct Z {};
1348 template<typename T> int *operator+(T, unsigned);
1349 }
1350
1351 int main() {
1352 N1::X<N2::Z> v;
1353 v.f(0);
1354 }
1355 }
1356
1357 namespace cwg385 { // cwg385: 2.8
1358 struct A { protected: void f(); };
1359 struct B : A { using A::f; };
1360 struct C : A { void g(B b) { b.f(); } };
1361 void h(B b) { b.f(); }
1362
1363 struct D { int n; }; // #cwg385-n
1364 struct E : protected D {}; // #cwg385-E
1365 struct F : E { friend int i(E); };
1366 int i(E e) { return e.n; }
1367 // expected-error@-1 {{'n' is a protected member of 'cwg385::D'}}
1368 // expected-note@#cwg385-E {{constrained by protected inheritance here}}
1369 // expected-note@#cwg385-n {{member is declared here}}
1370 }
1371
1372 namespace cwg387 { // cwg387: 2.8
1373 namespace old {
1374 template<typename T> class number {
1375 number(int); // #cwg387-number-ctor
1376 friend number gcd(number &x, number &y) {}
1377 };
1378
1379 void g() {
1380 number<double> a(3);
1381 // expected-error@-1 {{calling a private constructor of class 'cwg387::old::number<double>'}}
1382 // expected-note@#cwg387-number-ctor {{implicitly declared private here}}
1383 number<double> b(4);
1384 // expected-error@-1 {{calling a private constructor of class 'cwg387::old::number<double>'}}
1385 // expected-note@#cwg387-number-ctor {{implicitly declared private here}}
1386 a = gcd(a, b);
1387 b = gcd(3, 4);
1388 // expected-error@-1 {{use of undeclared identifier 'gcd'}}
1389 }
1390 }
1391
1392 namespace newer {
1393 template <typename T> class number {
1394 public:
1395 number(int);
1396 friend number gcd(number x, number y) { return 0; }
1397 };
1398
1399 void g() {
1400 number<double> a(3), b(4);
1401 a = gcd(a, b);
1402 b = gcd(3, 4);
1403 // expected-error@-1 {{use of undeclared identifier 'gcd'}}
1404 }
1405 }
1406 }
1407
1408 // FIXME: cwg388 needs libc++abi test
1409
1410 namespace cwg389 { // cwg389: no
1411 struct S {
1412 typedef struct {} A;
1413 typedef enum {} B;
1414 typedef struct {} const C; // #cwg389-C
1415 typedef enum {} const D; // #cwg389-D
1416 };
1417 template<typename> struct T {};
1418
1419 struct WithLinkage1 {};
1420 enum WithLinkage2 {};
1421 typedef struct {} *WithLinkage3a, WithLinkage3b;
1422 typedef enum {} WithLinkage4a, *WithLinkage4b;
1423 typedef S::A WithLinkage5;
1424 typedef const S::B WithLinkage6;
1425 typedef int WithLinkage7;
1426 typedef void (*WithLinkage8)(WithLinkage2 WithLinkage1::*, WithLinkage5 *);
1427 typedef T<WithLinkage5> WithLinkage9;
1428
1429 typedef struct {} *WithoutLinkage1; // #cwg389-no-link-1
1430 typedef enum {} const WithoutLinkage2; // #cwg389-no-link-2
1431 // These two types don't have linkage even though they are externally visible
1432 // and the ODR requires them to be merged across TUs.
1433 typedef S::C WithoutLinkage3;
1434 typedef S::D WithoutLinkage4;
1435 typedef void (*WithoutLinkage5)(int (WithoutLinkage3::*)(char));
1436
1437 #if __cplusplus >= 201103L
1438 // This has linkage even though its template argument does not.
1439 // FIXME: This is probably a defect.
1440 typedef T<WithoutLinkage1> WithLinkage10;
1441 #else
1442 typedef int WithLinkage10; // dummy
1443
1444 typedef T<WithLinkage1> GoodArg1;
1445 typedef T<WithLinkage2> GoodArg2;
1446 typedef T<WithLinkage3a> GoodArg3a;
1447 typedef T<WithLinkage3b> GoodArg3b;
1448 typedef T<WithLinkage4a> GoodArg4a;
1449 typedef T<WithLinkage4b> GoodArg4b;
1450 typedef T<WithLinkage5> GoodArg5;
1451 typedef T<WithLinkage6> GoodArg6;
1452 typedef T<WithLinkage7> GoodArg7;
1453 typedef T<WithLinkage8> GoodArg8;
1454 typedef T<WithLinkage9> GoodArg9;
1455
1456 typedef T<WithoutLinkage1> BadArg1;
1457 // expected-error@-1 {{template argument uses unnamed type}}
1458 // expected-note@#cwg389-no-link-1 {{unnamed type used in template argument was declared here}}
1459 typedef T<WithoutLinkage2> BadArg2;
1460 // expected-error@-1 {{template argument uses unnamed type}}
1461 // expected-note@#cwg389-no-link-2 {{unnamed type used in template argument was declared here}}
1462 typedef T<WithoutLinkage3> BadArg3;
1463 // expected-error@-1 {{template argument uses unnamed type}}
1464 // expected-note@#cwg389-C {{unnamed type used in template argument was declared here}}
1465 typedef T<WithoutLinkage4> BadArg4;
1466 // expected-error@-1 {{template argument uses unnamed type}}
1467 // expected-note@#cwg389-D {{unnamed type used in template argument was declared here}}
1468 typedef T<WithoutLinkage5> BadArg5;
1469 // expected-error@-1 {{template argument uses unnamed type}}
1470 // expected-note@#cwg389-C {{unnamed type used in template argument was declared here}}
1471 #endif
1472
1473 extern WithLinkage1 withLinkage1;
1474 extern WithLinkage2 withLinkage2;
1475 extern WithLinkage3a withLinkage3a;
1476 extern WithLinkage3b withLinkage3b;
1477 extern WithLinkage4a withLinkage4a;
1478 extern WithLinkage4b withLinkage4b;
1479 extern WithLinkage5 withLinkage5;
1480 extern WithLinkage6 withLinkage6;
1481 extern WithLinkage7 withLinkage7;
1482 extern WithLinkage8 withLinkage8;
1483 extern WithLinkage9 withLinkage9;
1484 extern WithLinkage10 withLinkage10;
1485
1486 // FIXME: These are all ill-formed.
1487 extern WithoutLinkage1 withoutLinkage1;
1488 extern WithoutLinkage2 withoutLinkage2;
1489 extern WithoutLinkage3 withoutLinkage3;
1490 extern WithoutLinkage4 withoutLinkage4;
1491 extern WithoutLinkage5 withoutLinkage5;
1492
1493 // OK, extern "C".
1494 extern "C" {
1495 extern WithoutLinkage1 cwg389_withoutLinkage1;
1496 extern WithoutLinkage2 cwg389_withoutLinkage2;
1497 extern WithoutLinkage3 cwg389_withoutLinkage3;
1498 extern WithoutLinkage4 cwg389_withoutLinkage4;
1499 extern WithoutLinkage5 cwg389_withoutLinkage5;
1500 }
1501
1502 // OK, defined.
1503 WithoutLinkage1 withoutLinkageDef1;
1504 WithoutLinkage2 withoutLinkageDef2 = WithoutLinkage2();
1505 WithoutLinkage3 withoutLinkageDef3 = {};
1506 WithoutLinkage4 withoutLinkageDef4 = WithoutLinkage4();
1507 WithoutLinkage5 withoutLinkageDef5;
1508
1509 void use(const void *);
1510 void use_all() {
1511 use(&withLinkage1); use(&withLinkage2); use(&withLinkage3a); use(&withLinkage3b);
1512 use(&withLinkage4a); use(&withLinkage4b); use(&withLinkage5); use(&withLinkage6);
1513 use(&withLinkage7); use(&withLinkage8); use(&withLinkage9); use(&withLinkage10);
1514
1515 use(&withoutLinkage1); use(&withoutLinkage2); use(&withoutLinkage3);
1516 use(&withoutLinkage4); use(&withoutLinkage5);
1517
1518 use(&cwg389_withoutLinkage1); use(&cwg389_withoutLinkage2);
1519 use(&cwg389_withoutLinkage3); use(&cwg389_withoutLinkage4);
1520 use(&cwg389_withoutLinkage5);
1521
1522 use(&withoutLinkageDef1); use(&withoutLinkageDef2); use(&withoutLinkageDef3);
1523 use(&withoutLinkageDef4); use(&withoutLinkageDef5);
1524 }
1525
1526 void local() {
1527 // FIXME: This is ill-formed.
1528 extern WithoutLinkage1 withoutLinkageLocal;
1529 }
1530 }
1531
1532 namespace cwg390 { // cwg390: 3.3
1533 template<typename T>
1534 struct A {
1535 A() { f(); }
1536 // 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>'}}
1537 // expected-note@#cwg390-A-int {{in instantiation of member function 'cwg390::A<int>::A' requested here}}
1538 // expected-note@#cwg390-f {{'f' declared here}}
1539 virtual void f() = 0; // #cwg390-f
1540 virtual ~A() = 0;
1541 };
1542 template<typename T> A<T>::~A() { T::error; }
1543 // expected-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}
1544 // expected-note@#cwg390-A-int {{in instantiation of member function 'cwg390::A<int>::~A' requested here}}
1545 template<typename T> void A<T>::f() { T::error; } // ok, not odr-used
1546 struct B : A<int> { // #cwg390-A-int
1547 void f() {}
1548 } b;
1549 }
1550
1551 namespace cwg391 { // cwg391: 2.8 c++11
1552 // FIXME: Should this apply to C++98 too?
1553 class A { A(const A&); }; // #cwg391-A
1554 A fa();
1555 const A &a = fa();
1556 // cxx98-error@-1 {{C++98 requires an accessible copy constructor for class 'cwg391::A' when binding a reference to a temporary; was private}}
1557 // cxx98-note@#cwg391-A {{implicitly declared private here}}
1558
1559 struct B { B(const B&) = delete; }; // #cwg391-B
1560 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
1561 B fb();
1562 const B &b = fb();
1563 // cxx98-error@-1 {{copying variable of type 'B' invokes deleted constructor}}
1564 // cxx98-note@#cwg391-B {{'B' has been explicitly marked deleted here}}
1565
1566 template<typename T>
1567 struct C {
1568 C(const C&) { T::error; }
1569 };
1570 C<int> fc();
1571 const C<int> &c = fc();
1572 }
1573
1574 // cwg392 is in cwg392.cpp
1575
1576 namespace cwg393 { // cwg393: 2.7
1577 template <typename T>
1578 struct S {};
1579
1580 void f1(S<int (*)[]>);
1581 void f2(S<int (&)[]>);
1582 void g(int(*S<int>::*)[]);
1583
1584 template<typename T>
1585 void sp_assert_convertible( T* ) {}
1586
1587 template<typename T, typename U>
1588 void h() {
1589 T (*p) [] = (U(*)[])0;
1590 sp_assert_convertible<T[]>( (U(*)[])0 );
1591 }
1592 } // namespace cwg393
1593
1594 // cwg394: na
1595
1596 namespace cwg395 { // cwg395: 3.0
1597 struct S {
1598 template <typename T, int N>(&operator T())[N];
1599 // expected-error@-1 {{cannot specify any part of a return type in the declaration of a conversion function}}
1600 template <typename T, int N> operator(T (&)[N])();
1601 // expected-error@-1 {{expected ')'}}
1602 // expected-note@-2 {{to match this '('}}
1603 // expected-error@-3 {{a type specifier is required for all declarations}}
1604 template <typename T> operator T *() const { return 0; }
1605 template <typename T, typename U> operator T U::*() const { return 0; }
1606 template <typename T, typename U> operator T (U::*)()() const { return 0; }
1607 // expected-error@-1 {{a type specifier is required for all declarations}}
1608 // expected-error@-2 {{conversion function cannot have any parameters}}
1609 // expected-error@-3 {{cannot specify any part of a return type in the declaration of a conversion function}}
1610 // expected-error@-4 {{conversion function cannot convert to a function type}}
1611
1612 };
1613
1614 struct null1_t {
1615 template <class T, class U> struct ptr_mem_fun_t {
1616 typedef T (U::*type)();
1617 };
1618
1619 template <class T, class U>
1620 operator typename ptr_mem_fun_t<T, U>::type() const { // #cwg395-conv-func
1621 return 0;
1622 }
1623 } null1;
1624 int (S::*p)() = null1;
1625 // expected-error@-1 {{no viable conversion from 'struct null1_t' to 'int (cwg395::S::*)()'}}
1626 // expected-note@#cwg395-conv-func {{candidate template ignored: couldn't infer template argument 'T'}}
1627
1628 template <typename T> using id = T;
1629 // cxx98-error@-1 {{alias declarations are a C++11 extension}}
1630
1631 struct T {
1632 template <typename T, int N> operator id<T[N]> &();
1633 template <typename T, typename U> operator id<T (U::*)()>() const;
1634 };
1635
1636 struct null2_t {
1637 template<class T, class U> using ptr_mem_fun_t = T (U::*)();
1638 // cxx98-error@-1 {{alias declarations are a C++11 extension}}
1639 template<class T, class U> operator ptr_mem_fun_t<T, U>() const { return 0; };
1640 } null2;
1641 int (S::*q)() = null2;
1642 }
1643
1644 namespace cwg396 { // cwg396: yes
1645 void f() {
1646 auto int a();
1647 // since-cxx11-error@-1 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}}
1648 // expected-error@-2 {{illegal storage class on function}}
1649 int (i); // #cwg396-i
1650 auto int (i);
1651 // since-cxx11-error@-1 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}}
1652 // expected-error@-2 {{redefinition of 'i'}}
1653 // expected-note@#cwg396-i {{previous definition is here}}
1654 }
1655 }
1656
1657 // cwg397: sup 1823
1658
1659 namespace cwg398 { // cwg398: yes
1660 namespace example1 {
1661 struct S {
1662 static int const I = 42;
1663 };
1664 template <int N> struct X {};
1665 template <typename T> void f(X<T::I> *) {}
1666 template <typename T> void f(X<T::J> *) {}
1667 void foo() { f<S>(0); }
1668 }
1669
1670 namespace example2 {
1671 template <int I> struct X {};
1672 template <template <class T> class> struct Z {};
1673 template <class T> void f(typename T::Y *) {} // #cwg398-f
1674 template <class T> void g(X<T::N> *) {} // #cwg398-g
1675 template <class T> void h(Z<T::template TT> *) {} // #cwg398-h
1676 struct A {};
1677 struct B {
1678 int Y;
1679 };
1680 struct C {
1681 typedef int N;
1682 };
1683 struct D {
1684 typedef int TT;
1685 };
1686
1687 void test() {
1688 f<A>(0);
1689 // expected-error@-1 {{no matching function for call to 'f'}}
1690 // expected-note@#cwg398-f {{candidate template ignored: substitution failure [with T = A]: no type named 'Y' in 'cwg398::example2::A'}}
1691 f<B>(0);
1692 // expected-error@-1 {{no matching function for call to 'f'}}
1693 // expected-note@#cwg398-f {{candidate template ignored: substitution failure [with T = B]: typename specifier refers to non-type member 'Y' in 'cwg398::example2::B'}}
1694 g<C>(0);
1695 // expected-error@-1 {{no matching function for call to 'g'}}
1696 // expected-note@#cwg398-g {{candidate template ignored: substitution failure [with T = C]: missing 'typename' prior to dependent type name 'C::N'}}
1697 h<D>(0);
1698 // expected-error@-1 {{no matching function for call to 'h'}}
1699 // expected-note@#cwg398-h {{candidate template ignored: substitution failure [with T = D]: 'TT' following the 'template' keyword does not refer to a template}}
1700 }
1701 }
1702 }
1703
1704 namespace cwg399 { // cwg399: 11
1705 // NB: reuse cwg244 test
1706 struct B {}; // #cwg399-B
1707 struct D : B {};
1708
1709 D D_object;
1710 typedef B B_alias;
1711 B* B_ptr = &D_object;
1712
1713 void f() {
1714 D_object.~B();
1715 // expected-error@-1 {{destructor type 'cwg399::B' in object destruction expression does not match the type 'D' of the object being destroyed}}
1716 // expected-note@#cwg399-B {{type 'cwg399::B' found by destructor name lookup}}
1717 D_object.B::~B();
1718 D_object.D::~B(); // FIXME: Missing diagnostic for this.
1719 B_ptr->~B();
1720 B_ptr->~B_alias();
1721 B_ptr->B_alias::~B();
1722 B_ptr->B_alias::~B_alias();
1723 B_ptr->cwg399::~B();
1724 // expected-error@-1 {{no member named '~B' in namespace 'cwg399'}}
1725 B_ptr->cwg399::~B_alias();
1726 // expected-error@-1 {{no member named '~B' in namespace 'cwg399'}}
1727 }
1728
1729 template<typename T, typename U>
1730 void f(T *B_ptr, U D_object) {
1731 D_object.~B(); // FIXME: Missing diagnostic for this.
1732 D_object.B::~B();
1733 D_object.D::~B(); // FIXME: Missing diagnostic for this.
1734 B_ptr->~B();
1735 B_ptr->~B_alias();
1736 B_ptr->B_alias::~B();
1737 B_ptr->B_alias::~B_alias();
1738 B_ptr->cwg399::~B();
1739 // expected-error@-1 {{'cwg399' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
1740 B_ptr->cwg399::~B_alias();
1741 // expected-error@-1 {{'cwg399' does not refer to a type name in pseudo-destructor expression; expected the name of type 'T'}}
1742 }
1743 template void f<B, D>(B*, D);
1744
1745 namespace N {
1746 template<typename T> struct E {};
1747 typedef E<int> F;
1748 }
1749 void g(N::F f) {
1750 typedef N::F G; // #cwg399-G
1751 f.~G();
1752 f.G::~E();
1753 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
1754 f.G::~F();
1755 // expected-error@-1 {{undeclared identifier 'F' in destructor name}}
1756 f.G::~G();
1757 // This is technically ill-formed; E is looked up in 'N::' and names the
1758 // class template, not the injected-class-name of the class. But that's
1759 // probably a bug in the standard.
1760 f.N::F::~E();
1761 // expected-error@-1 {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
1762 // This is valid; we look up the second F in the same scope in which we
1763 // found the first one, that is, 'N::'.
1764 f.N::F::~F();
1765 // This is technically ill-formed; G is looked up in 'N::' and is not found.
1766 // Rejecting this seems correct, but most compilers accept, so we do also.
1767 f.N::F::~G();
1768 // expected-error@-1 {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}
1769 // expected-note@#cwg399-G {{type 'G' (aka 'E<int>') found by destructor name lookup}}
1770 }
1771
1772 // Bizarrely, compilers perform lookup in the scope for qualified destructor
1773 // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
1774 // this.
1775 namespace QualifiedLookupInScope {
1776 namespace N {
1777 template <typename> struct S { struct Inner {}; };
1778 }
1779 template <typename U> void f(typename N::S<U>::Inner *p) {
1780 typedef typename N::S<U>::Inner T;
1781 p->::cwg399::QualifiedLookupInScope::N::S<U>::Inner::~T();
1782 // expected-error@-1 {{no type named 'T' in 'cwg399::QualifiedLookupInScope::N::S<int>'}}
1783 // expected-note@#cwg399-f {{in instantiation of function template specialization 'cwg399::QualifiedLookupInScope::f<int>' requested here}}
1784 }
1785 template void f<int>(N::S<int>::Inner *); // #cwg399-f
1786
1787 template <typename U> void g(U *p) {
1788 typedef U T;
1789 p->T::~T();
1790 p->U::~T();
1791 p->::cwg399::QualifiedLookupInScope::N::S<int>::Inner::~T();
1792 // expected-error@-1 {{'T' does not refer to a type name in pseudo-destructor expression; expected the name of type 'U'}}
1793 }
1794 template void g(N::S<int>::Inner *);
1795 }
1796 }