Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr3xx.cpp
blobaebb33fdd583cf3d893741972357f2118b71e870
1 // RUN: %clang_cc1 -std=c++23 -verify=expected,cxx20_23,cxx23 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++20 -verify=expected,cxx98_20,cxx20_23 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++17 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++14 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++11 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++98 -verify=expected,cxx98_17,cxx98_20 -triple %itanium_abi_triple %s -fexceptions -fcxx-exceptions -pedantic-errors
8 namespace dr300 { // dr300: yes
9 template<typename R, typename A> void f(R (&)(A)) {}
10 int g(int);
11 void h() { f(g); }
14 namespace dr301 { // dr301: yes
15 // see also dr38
16 struct S;
17 template<typename T> void operator+(T, T);
18 void operator-(S, S);
20 void f() {
21 bool a = (void(*)(S, S))operator+<S> < // expected-warning {{ordered comparison of function pointers}}
22 (void(*)(S, S))operator+<S>;
23 bool b = (void(*)(S, S))operator- < // cxx20_23-note {{to match this '<'}} cxx98_17-warning {{ordered comparison of function pointers}}
24 (void(*)(S, S))operator-; // cxx20_23-error {{expected '>'}}
25 bool c = (void(*)(S, S))operator+ < // expected-note {{to match this '<'}}
26 (void(*)(S, S))operator-; // expected-error {{expected '>'}}
29 template<typename T> void f() {
30 typename T::template operator+<int> a; // expected-error {{typename specifier refers to a non-type template}} expected-error +{{}}
31 // FIXME: This shouldn't say (null).
32 class T::template operator+<int> b; // expected-error {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}}
33 enum T::template operator+<int> c; // expected-error {{expected identifier}}
34 enum T::template operator+<int>::E d; // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}} expected-error {{forward reference}}
35 enum T::template X<int>::E e;
36 T::template operator+<int>::foobar(); // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}}
37 T::template operator+<int>(0); // ok
40 template<typename T> class operator&<T*> {}; // expected-error +{{}}
41 template<typename T> class T::operator& {}; // expected-error +{{}}
42 template<typename T> class S::operator&<T*> {}; // expected-error +{{}}
45 namespace dr302 { // dr302: yes
46 struct A { A(); ~A(); };
47 #if __cplusplus < 201103L
48 struct B { // expected-error {{implicit default constructor for 'dr302::B' must explicitly initialize the const member 'n'}}
49 const int n; // expected-note {{declared here}}
50 A a;
51 } b = B(); // expected-note {{first required here}}
52 // Trivial default constructor C::C() is not called here.
53 struct C {
54 const int n;
55 } c = C();
56 #else
57 struct B {
58 const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
59 A a;
60 } b = B(); // expected-error {{call to implicitly-deleted default constructor}}
61 // C::C() is called here, because even though it's trivial, it's deleted.
62 struct C {
63 const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
64 } c = C(); // expected-error {{call to implicitly-deleted default constructor}}
65 struct D {
66 const int n = 0;
67 } d = D();
68 #endif
71 // dr303: na
73 namespace dr304 { // dr304: yes
74 typedef int &a;
75 int n = a(); // expected-error {{requires an initializer}}
77 struct S { int &b; };
78 int m = S().b;
79 #if __cplusplus < 201103L
80 // expected-error@-3 {{requires an initializer}}
81 // expected-note@-3 {{in value-initialization}}
82 #else
83 // expected-error@-5 {{deleted}}
84 // expected-note@-7 {{reference}}
85 #endif
88 namespace dr305 { // dr305: no
89 struct A {
90 typedef A C;
92 void f(A *a) {
93 struct A {};
94 a->~A();
95 a->~C();
97 typedef A B;
98 void g(B *b) {
99 b->~B();
100 b->~C();
102 void h(B *b) {
103 struct B {}; // expected-note {{type 'B' found by destructor name lookup}}
104 b->~B(); // expected-error {{does not match}}
107 template<typename T> struct X {};
108 void i(X<int>* x) {
109 struct X {};
110 x->~X<int>();
111 x->~X();
112 x->~X<char>(); // expected-error {{no member named}}
115 #if __cplusplus >= 201103L
116 struct Y {
117 template<typename T> using T1 = Y;
119 template<typename T> using T2 = Y;
120 void j(Y *y) {
121 y->~T1<int>();
122 y->~T2<int>();
124 struct Z {
125 template<typename T> using T2 = T;
127 void k(Z *z) {
128 z->~T1<int>(); // expected-error {{no member named 'T1' in 'dr305::Z'}}
129 z->~T2<int>(); // expected-error {{no member named '~int'}}
130 z->~T2<Z>();
133 // FIXME: This is valid.
134 namespace Q {
135 template<typename A> struct R {};
137 template<typename A> using R = Q::R<int>;
138 void qr(Q::R<int> x) { x.~R<char>(); } // expected-error {{no member named}}
139 #endif
142 namespace dr306 { // dr306: dup 39
143 struct A { struct B {}; };
144 struct C { typedef A::B B; };
145 struct D : A, A::B, C {};
146 D::B b;
148 struct X {}; // expected-note {{member type 'dr306::X' found}}
149 template<typename T> struct Y { typedef T X; }; // expected-note {{member type 'const dr306::X' found}}
150 template<typename T> struct Z : X, Y<T> {};
151 Z<X>::X zx;
152 Z<const X>::X zcx; // expected-error {{member 'X' found in multiple base classes of different types}}
155 // dr307: na
157 namespace dr308 { // dr308: yes
158 // This is mostly an ABI library issue.
159 struct A {};
160 struct B : A {};
161 struct C : A {};
162 struct D : B, C {};
163 void f() {
164 // NB: the warning here is correct despite being the opposite of the
165 // comments in the catch handlers. The "unreachable" comment is correct
166 // because there is an ambiguous base path to A from the D that is thrown.
167 // The warnings generated are also correct because the handlers handle
168 // const B& and const A& and we don't check to see if other derived classes
169 // exist that would cause an ambiguous base path. We issue the diagnostic
170 // despite the potential for a false positive because users are not
171 // expected to have ambiguous base paths all that often, so the false
172 // positive rate should be acceptably low.
173 try {
174 throw D();
175 } catch (const A&) { // expected-note {{for type 'const A &'}}
176 // unreachable
177 } catch (const B&) { // expected-warning {{exception of type 'const B &' will be caught by earlier handler}}
178 // get here instead
183 // dr309: dup 485
185 namespace dr311 { // dr311: yes
186 namespace X { namespace Y {} }
187 namespace X::Y {}
188 #if __cplusplus <= 201402L
189 // expected-error@-2 {{define each namespace separately}}
190 #endif
191 namespace X {
192 namespace X::Y {}
193 #if __cplusplus <= 201402L
194 // expected-error@-2 {{define each namespace separately}}
195 #endif
197 // FIXME: The diagnostics here are not very good.
198 namespace ::dr311::X {} // expected-error 2+{{}} // expected-warning {{extra qual}}
201 // dr312: dup 616
203 namespace dr313 { // dr313: dup 299 c++11
204 struct A { operator int() const; };
205 int *p = new int[A()];
206 #if __cplusplus < 201103L
207 // FIXME: should this be available in c++98 mode? expected-error@-2 {{extension}}
208 #endif
211 namespace dr314 { // dr314: no
212 // NB: dup 1710
213 template <typename T> struct A {
214 template <typename U> struct B {};
216 template <typename T> struct C : public A<T>::template B<T> {
217 C() : A<T>::template B<T>() {}
219 template <typename T> struct C2 : public A<T>::B<T> {
220 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
221 C2() : A<T>::B<T>() {}
222 // expected-error@-1 {{use 'template' keyword to treat 'B' as a dependent template name}}
224 } // namespace dr314
226 // dr315: na
227 // dr316: sup 1004
229 namespace dr317 { // dr317: 3.5
230 void f() {} // expected-note {{previous}}
231 inline void f(); // expected-error {{inline declaration of 'f' follows non-inline definition}}
233 int g();
234 int n = g();
235 inline int g() { return 0; }
237 int h();
238 int m = h();
239 int h() { return 0; } // expected-note {{previous}}
240 inline int h(); // expected-error {{inline declaration of 'h' follows non-inline definition}}
243 namespace dr318 { // dr318: sup 1310
244 struct A {};
245 struct A::A a;
248 namespace dr319 { // dr319: no
249 // FIXME: dup dr389
250 // FIXME: We don't have a diagnostic for a name with linkage
251 // having a type without linkage.
252 typedef struct {
253 int i;
254 } *ps;
255 extern "C" void f(ps);
256 void g(ps); // FIXME: ill-formed, type 'ps' has no linkage
258 static enum { e } a1;
259 enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage
261 enum { n1 = 1u };
262 typedef int (*pa)[n1];
263 pa parr; // ok, type has linkage despite using 'n1'
265 template<typename> struct X {};
267 void f() {
268 struct A { int n; };
269 extern A a; // FIXME: ill-formed
270 X<A> xa;
272 typedef A B;
273 extern B b; // FIXME: ill-formed
274 X<B> xb;
276 const int n = 1;
277 typedef int (*C)[n];
278 extern C c; // ok
279 X<C> xc;
281 #if __cplusplus < 201103L
282 // expected-error@-12 {{uses local type 'A'}}
283 // expected-error@-9 {{uses local type 'A'}}
284 #endif
287 namespace dr320 { // dr320: yes
288 #if __cplusplus >= 201103L
289 struct X {
290 constexpr X() {}
291 constexpr X(const X &x) : copies(x.copies + 1) {}
292 unsigned copies = 0;
294 constexpr X f(X x) { return x; }
295 constexpr unsigned g(X x) { return x.copies; }
296 static_assert(f(X()).copies == g(X()) + 1, "expected one extra copy for return value");
297 #endif
300 namespace dr321 { // dr321: dup 557
301 namespace N {
302 template<int> struct A {
303 template<int> struct B;
305 template<> template<> struct A<0>::B<0>;
306 void f(A<0>::B<0>);
308 template<> template<> struct N::A<0>::B<0> {};
310 template<typename T> void g(T t) { f(t); }
311 template void g(N::A<0>::B<0>);
313 namespace N {
314 template<typename> struct I { friend bool operator==(const I&, const I&); };
316 N::I<int> i, j;
317 bool x = i == j;
320 namespace dr322 { // dr322: yes
321 struct A {
322 template<typename T> operator T&();
323 } a;
324 int &r = static_cast<int&>(a);
325 int &s = a;
328 // dr323: no
330 namespace dr324 { // dr324: yes
331 struct S { int n : 1; } s; // expected-note 3{{bit-field is declared here}}
332 int &a = s.n; // expected-error {{non-const reference cannot bind to bit-field}}
333 int *b = &s.n; // expected-error {{address of bit-field}}
334 int &c = (s.n = 0); // expected-error {{non-const reference cannot bind to bit-field}}
335 int *d = &(s.n = 0); // expected-error {{address of bit-field}}
336 int &e = true ? s.n : s.n; // expected-error {{non-const reference cannot bind to bit-field}}
337 int *f = &(true ? s.n : s.n); // expected-error {{address of bit-field}}
338 int &g = (void(), s.n); // expected-error {{non-const reference cannot bind to bit-field}}
339 int *h = &(void(), s.n); // expected-error {{address of bit-field}}
340 int *i = &++s.n; // expected-error {{address of bit-field}}
343 namespace dr326 { // dr326: yes
344 struct S {};
345 int test[__is_trivially_constructible(S, const S&) ? 1 : -1];
348 namespace dr327 { // dr327: dup 538
349 struct A;
350 class A {};
352 class B;
353 struct B {};
356 namespace dr328 { // dr328: yes
357 struct A; // expected-note 3{{forward declaration}}
358 struct B { A a; }; // expected-error {{incomplete}}
359 template<typename> struct C { A a; }; // expected-error {{incomplete}}
360 A *p = new A[0]; // expected-error {{incomplete}}
363 namespace dr329 { // dr329: 3.5
364 struct B {};
365 template<typename T> struct A : B {
366 friend void f(A a) { g(a); }
367 friend void h(A a) { g(a); } // expected-error {{undeclared}}
368 friend void i(B b) {} // expected-error {{redefinition}} expected-note {{previous}}
370 A<int> a;
371 A<char> b; // expected-note {{instantiation}}
373 void test() {
374 h(a); // expected-note {{instantiation}}
378 namespace dr330 { // dr330: 7
379 // Conversions between P and Q will be allowed by P0388.
380 typedef int *(*P)[3];
381 typedef const int *const (*Q)[3];
382 typedef const int *Qinner[3];
383 typedef Qinner const *Q2; // same as Q, but 'const' written outside the array type
384 typedef const int *const (*R)[4];
385 typedef const int *const (*S)[];
386 typedef const int *(*T)[];
387 void f(P p, Q q, Q2 q2, R r, S s, T t) {
388 q = p; // ok
389 q2 = p; // ok
390 r = p; // expected-error {{incompatible}}
391 s = p;
392 #if __cplusplus < 202002
393 // expected-error@-2 {{incompatible}} (fixed by p0388)
394 #endif
395 t = p; // expected-error {{incompatible}}
396 s = q;
397 #if __cplusplus < 202002
398 // expected-error@-2 {{incompatible}} (fixed by p0388)
399 #endif
400 s = q2;
401 #if __cplusplus < 202002
402 // expected-error@-2 {{incompatible}} (fixed by p0388)
403 #endif
404 s = t; // ok, adding const
405 t = s; // expected-error {{discards qualifiers}}
406 (void) const_cast<P>(q);
407 (void) const_cast<P>(q2);
408 (void) const_cast<Q>(p);
409 (void) const_cast<Q2>(p);
410 (void) const_cast<S>(p); // expected-error {{not allowed}} (for now)
411 (void) const_cast<P>(s); // expected-error {{not allowed}} (for now)
412 (void) const_cast<S>(q); // expected-error {{not allowed}}
413 (void) const_cast<S>(q2); // expected-error {{not allowed}}
414 (void) const_cast<Q>(s); // expected-error {{not allowed}}
415 (void) const_cast<Q2>(s); // expected-error {{not allowed}}
416 (void) const_cast<T>(s);
417 (void) const_cast<S>(t);
418 (void) const_cast<T>(q); // expected-error {{not allowed}}
419 (void) const_cast<Q>(t); // expected-error {{not allowed}}
421 (void) reinterpret_cast<P>(q); // expected-error {{casts away qualifiers}}
422 (void) reinterpret_cast<P>(q2); // expected-error {{casts away qualifiers}}
423 (void) reinterpret_cast<Q>(p);
424 (void) reinterpret_cast<Q2>(p);
425 (void) reinterpret_cast<S>(p);
426 (void) reinterpret_cast<P>(s); // expected-error {{casts away qualifiers}}
427 (void) reinterpret_cast<S>(q);
428 (void) reinterpret_cast<S>(q2);
429 (void) reinterpret_cast<Q>(s);
430 (void) reinterpret_cast<Q2>(s);
431 (void) reinterpret_cast<T>(s); // expected-error {{casts away qualifiers}}
432 (void) reinterpret_cast<S>(t);
433 (void) reinterpret_cast<T>(q); // expected-error {{casts away qualifiers}}
434 (void) reinterpret_cast<Q>(t);
437 namespace swift_17882 {
438 typedef const char P[72];
439 typedef int *Q;
440 void f(P &pr, P *pp) {
441 (void) reinterpret_cast<const Q&>(pr);
442 (void) reinterpret_cast<const Q*>(pp);
445 struct X {};
446 typedef const volatile int A[1][2][3];
447 typedef int *const X::*volatile *B1;
448 typedef int *const X::* *B2;
449 typedef int *X::* volatile *B3;
450 typedef volatile int *(*const B4)[4];
451 void f(A *a) {
452 (void) reinterpret_cast<B1*>(a);
453 (void) reinterpret_cast<B2*>(a); // expected-error {{casts away qualifiers}}
454 (void) reinterpret_cast<B3*>(a); // expected-error {{casts away qualifiers}}
455 (void) reinterpret_cast<B4*>(a);
460 namespace dr331 { // dr331: yes
461 struct A {
462 A(volatile A&); // expected-note 2{{candidate}}
463 } const a, b(a); // expected-error 2{{no matching constructor}}
466 namespace dr332 { // dr332: dup 577
467 void f(volatile void); // expected-error {{'void' as parameter must not have type qualifiers}}
468 // cxx20_23-warning@-1 {{volatile-qualified parameter type 'volatile void' is deprecated}}
469 void g(const void); // expected-error {{'void' as parameter must not have type qualifiers}}
470 void h(int n, volatile void); // expected-error {{'void' must be the first and only parameter}}
471 // cxx20_23-warning@-1 {{volatile-qualified parameter type 'volatile void' is deprecated}}
474 namespace dr333 { // dr333: yes
475 int n = 0;
476 int f(int(n));
477 int g((int(n)));
478 int h = f(g);
481 namespace dr334 { // dr334: yes
482 template<typename T> void f() {
483 T x;
484 f((x, 123));
486 struct S {
487 friend S operator,(S, int);
488 friend void f(S);
490 template void f<S>();
493 // dr335: no
495 namespace dr336 { // dr336: yes
496 namespace Pre {
497 template<class T1> class A {
498 template<class T2> class B {
499 template<class T3> void mf1(T3);
500 void mf2();
503 template<> template<class X> class A<int>::B {};
504 template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {} // expected-error {{does not match}}
505 template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
507 namespace Post {
508 template<class T1> class A {
509 template<class T2> class B {
510 template<class T3> void mf1(T3);
511 void mf2();
514 template<> template<class X> class A<int>::B {
515 template<class T> void mf1(T);
517 template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {}
518 // FIXME: This diagnostic isn't very good.
519 template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
523 namespace dr337 { // dr337: yes
524 template<typename T> void f(T (*)[1]);
525 template<typename T> int &f(...);
527 struct A { virtual ~A() = 0; };
528 int &r = f<A>(0);
530 // FIXME: The language rules here are completely broken. We cannot determine
531 // whether an incomplete type is abstract. See DR1640, which will probably
532 // supersede this one and remove this rule.
533 struct B;
534 int &s = f<B>(0); // expected-error {{of type 'void'}}
535 struct B { virtual ~B() = 0; };
538 namespace dr339 { // dr339: yes
539 template <int I> struct A { static const int value = I; };
541 char xxx(int);
542 char (&xxx(float))[2];
544 template<class T> A<sizeof(xxx((T)0))> f(T) {} // expected-note {{candidate}}
546 void test() {
547 A<1> a = f(0);
548 A<2> b = f(0.0f);
549 A<3> c = f("foo"); // expected-error {{no matching function}}
553 char f(int);
554 int f(...);
556 template <class T> struct conv_int {
557 static const bool value = sizeof(f(T())) == 1;
560 template <class T> bool conv_int2(A<sizeof(f(T()))> p);
562 template<typename T> A<sizeof(f(T()))> make_A();
564 int a[conv_int<char>::value ? 1 : -1];
565 bool b = conv_int2<char>(A<1>());
566 A<1> c = make_A<char>();
569 namespace dr340 { // dr340: yes
570 struct A { A(int); };
571 struct B { B(A, A, int); };
572 int x, y;
573 B b(A(x), A(y), 3);
576 namespace dr341 { // dr341: sup 1708
577 namespace A {
578 int n;
579 extern "C" int &dr341_a = n; // expected-note {{previous}} expected-note {{declared with C language linkage here}}
581 namespace B {
582 extern "C" int &dr341_a = dr341_a; // expected-error {{redefinition}}
584 extern "C" void dr341_b(); // expected-note {{declared with C language linkage here}}
586 int dr341_a; // expected-error {{declaration of 'dr341_a' in global scope conflicts with declaration with C language linkage}}
587 int dr341_b; // expected-error {{declaration of 'dr341_b' in global scope conflicts with declaration with C language linkage}}
588 int dr341_c; // expected-note {{declared in global scope here}}
589 int dr341_d; // expected-note {{declared in global scope here}}
590 namespace dr341 {
591 extern "C" int dr341_c; // expected-error {{declaration of 'dr341_c' with C language linkage conflicts with declaration in global scope}}
592 extern "C" void dr341_d(); // expected-error {{declaration of 'dr341_d' with C language linkage conflicts with declaration in global scope}}
594 namespace A { extern "C" int dr341_e; } // expected-note {{previous}}
595 namespace B { extern "C" void dr341_e(); } // expected-error {{redefinition of 'dr341_e' as different kind of symbol}}
598 // dr342: na
600 namespace dr343 { // dr343: no
601 // FIXME: dup 1710
602 template<typename T> struct A {
603 template<typename U> struct B {};
605 // FIXME: In these contexts, the 'template' keyword is optional.
606 template<typename T> struct C : public A<T>::B<T> { // expected-error {{use 'template'}}
607 C() : A<T>::B<T>() {} // expected-error {{use 'template'}}
611 namespace dr344 { // dr344: dup 1435
612 struct A { inline virtual ~A(); };
613 struct B { friend A::~A(); };
616 namespace dr345 { // dr345: yes
617 struct A {
618 struct X {};
619 int X; // expected-note {{here}}
621 struct B {
622 struct X {};
624 template <class T> void f(T t) { typename T::X x; } // expected-error {{refers to non-type member 'X'}}
625 void f(A a, B b) {
626 f(b);
627 f(a); // expected-note {{instantiation}}
631 // dr346: na
633 namespace dr347 { // dr347: yes
634 struct base {
635 struct nested;
636 static int n;
637 static void f();
638 void g();
641 struct derived : base {};
643 struct derived::nested {}; // expected-error {{no struct named 'nested'}}
644 int derived::n; // expected-error {{no member named 'n'}}
645 void derived::f() {} // expected-error {{does not match any}}
646 void derived::g() {} // expected-error {{does not match any}}
649 // dr348: na
651 namespace dr349 { // dr349: no
652 struct A {
653 template <class T> operator T ***() {
654 int ***p = 0;
655 return p; // cxx98_20-error {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}}
656 // cxx23-error@-1 {{cannot initialize return object of type 'const int ***' with an rvalue of type 'int ***'}}
660 // FIXME: This is valid.
661 A a;
662 const int *const *const *p1 = a; // expected-note {{in instantiation of}}
664 struct B {
665 template <class T> operator T ***() {
666 const int ***p = 0;
667 return p;
671 // FIXME: This is invalid.
672 B b;
673 const int *const *const *p2 = b;
676 // dr351: na
678 namespace dr352 { // dr352: yes
679 namespace example1 {
680 namespace A {
681 enum E {};
682 template<typename R, typename A> void foo(E, R (*)(A)); // expected-note 2{{couldn't infer template argument 'R'}}
685 template<typename T> void arg(T);
686 template<typename T> int arg(T) = delete; // expected-note {{here}} expected-error 0-1{{extension}}
688 void f(A::E e) {
689 foo(e, &arg); // expected-error {{no matching function}}
691 using A::foo;
692 foo<int, int>(e, &arg); // expected-error {{deleted}}
695 int arg(int);
697 void g(A::E e) {
698 foo(e, &arg); // expected-error {{no matching function}}
700 using A::foo;
701 foo<int, int>(e, &arg); // ok, uses non-template
705 namespace contexts {
706 template<int I> void f1(int (&)[I]);
707 template<int I> void f2(int (&)[I+1]); // expected-note {{couldn't infer}}
708 template<int I> void f3(int (&)[I+1], int (&)[I]);
709 void f() {
710 int a[4];
711 int b[3];
712 f1(a);
713 f2(a); // expected-error {{no matching function}}
714 f3(a, b);
717 template<int I> struct S {};
718 template<int I> void g1(S<I>);
719 template<int I> void g2(S<I+1>); // expected-note {{couldn't infer}}
720 template<int I> void g3(S<I+1>, S<I>);
721 void g() {
722 S<4> a;
723 S<3> b;
724 g1(a);
725 g2(a); // expected-error {{no matching function}}
726 g3(a, b);
729 template<typename T> void h1(T = 0); // expected-note {{couldn't infer}}
730 template<typename T> void h2(T, T = 0);
731 void h() {
732 h1(); // expected-error {{no matching function}}
733 h1(0);
734 h1<int>();
735 h2(0);
738 template<typename T> int tmpl(T);
739 template<typename R, typename A> void i1(R (*)(A)); // expected-note 3{{couldn't infer}}
740 template<typename R, typename A> void i2(R, A, R (*)(A)); // expected-note {{not viable}}
741 void i() {
742 extern int single(int);
743 i1(single);
744 i2(0, 0, single);
746 extern int ambig(float), ambig(int);
747 i1(ambig); // expected-error {{no matching function}}
748 i2(0, 0, ambig);
750 extern void no_match(float), no_match(int);
751 i1(no_match); // expected-error {{no matching function}}
752 i2(0, 0, no_match); // expected-error {{no matching function}}
754 i1(tmpl); // expected-error {{no matching function}}
755 i2(0, 0, tmpl);
759 template<typename T> struct is_int;
760 template<> struct is_int<int> {};
762 namespace example2 {
763 template<typename T> int f(T (*p)(T)) { is_int<T>(); }
764 int g(int);
765 int g(char);
766 int i = f(g);
769 namespace example3 {
770 template<typename T> int f(T, T (*p)(T)) { is_int<T>(); }
771 int g(int);
772 char g(char);
773 int i = f(1, g);
776 namespace example4 {
777 template <class T> int f(T, T (*p)(T)) { is_int<T>(); }
778 char g(char);
779 template <class T> T g(T);
780 int i = f(1, g);
783 namespace example5 {
784 template<int I> class A {};
785 template<int I> void g(A<I+1>); // expected-note {{couldn't infer}}
786 template<int I> void f(A<I>, A<I+1>);
787 void h(A<1> a1, A<2> a2) {
788 g(a1); // expected-error {{no matching function}}
789 g<0>(a1);
790 f(a1, a2);
795 // dr353 needs an IRGen test.
797 namespace dr354 { // dr354: yes c++11
798 // FIXME: Should we allow this in C++98 too?
799 struct S {};
801 template<int*> struct ptr {}; // expected-note 0-4{{here}}
802 ptr<0> p0;
803 ptr<(int*)0> p1;
804 ptr<(float*)0> p2;
805 ptr<(int S::*)0> p3;
806 #if __cplusplus < 201103L
807 // expected-error@-5 {{does not refer to any decl}}
808 // expected-error@-5 {{does not refer to any decl}}
809 // expected-error@-5 {{does not refer to any decl}}
810 // expected-error@-5 {{does not refer to any decl}}
811 #elif __cplusplus <= 201402L
812 // expected-error@-10 {{must be cast}}
813 // ok
814 // expected-error@-10 {{does not match}}
815 // expected-error@-10 {{does not match}}
816 #else
817 // expected-error@-15 {{conversion from 'int' to 'int *' is not allowed}}
818 // ok
819 // expected-error@-15 {{'float *' is not implicitly convertible to 'int *'}}
820 // expected-error@-15 {{'int dr354::S::*' is not implicitly convertible to 'int *'}}
821 #endif
823 template<int*> int both();
824 template<int> int both();
825 int b0 = both<0>();
826 int b1 = both<(int*)0>();
827 #if __cplusplus < 201103L
828 // expected-error@-2 {{no matching function}}
829 // expected-note@-6 {{candidate}}
830 // expected-note@-6 {{candidate}}
831 #endif
833 template<int S::*> struct ptr_mem {}; // expected-note 0-4{{here}}
834 ptr_mem<0> m0;
835 ptr_mem<(int S::*)0> m1;
836 ptr_mem<(float S::*)0> m2;
837 ptr_mem<(int *)0> m3;
838 #if __cplusplus < 201103L
839 // expected-error@-5 {{cannot be converted}}
840 // expected-error@-5 {{is not a pointer to member constant}}
841 // expected-error@-5 {{cannot be converted}}
842 // expected-error@-5 {{cannot be converted}}
843 #elif __cplusplus <= 201402L
844 // expected-error@-10 {{must be cast}}
845 // ok
846 // expected-error@-10 {{does not match}}
847 // expected-error@-10 {{does not match}}
848 #else
849 // expected-error@-15 {{conversion from 'int' to 'int dr354::S::*' is not allowed}}
850 // ok
851 // expected-error@-15 {{'float dr354::S::*' is not implicitly convertible to 'int dr354::S::*'}}
852 // expected-error@-15 {{'int *' is not implicitly convertible to 'int dr354::S::*'}}
853 #endif
856 struct dr355_S; // dr355: yes
857 struct ::dr355_S {}; // expected-warning {{extra qualification}}
858 namespace dr355 { struct ::dr355_S s; }
860 // dr356: na
862 namespace dr357 { // dr357: yes
863 template<typename T> struct A {
864 void f() const; // expected-note {{const qualified}}
866 template<typename T> void A<T>::f() {} // expected-error {{does not match}}
868 struct B {
869 template<typename T> void f();
871 template<typename T> void B::f() const {} // expected-error {{does not match}}
874 namespace dr358 { // dr358: yes
875 extern "C" void dr358_f();
876 namespace N {
877 int var;
878 extern "C" void dr358_f() { var = 10; }
882 namespace dr359 { // dr359: yes
883 // Note, the example in the DR is wrong; it doesn't contain an anonymous
884 // union.
885 struct E {
886 union {
887 struct {
888 int x;
889 } s;
890 } v;
892 union {
893 struct { // expected-error {{extension}}
894 int x;
895 } s;
897 struct S { // expected-error {{types cannot be declared in an anonymous union}}
898 int x;
899 } t;
901 union { // expected-error {{extension}}
902 int u;
908 namespace dr360 { // dr360: yes
909 struct A {
910 int foo();
911 int bar();
913 protected:
914 int baz();
917 struct B : A {
918 private:
919 using A::foo; // #dr360-foo-using-decl
920 protected:
921 using A::bar; // #dr360-bar-using-decl
922 public:
923 using A::baz;
926 int main() {
927 int foo = B().foo(); // expected-error {{is a private member}}
928 // expected-note@#dr360-foo-using-decl {{declared private here}}
929 int bar = B().bar(); // expected-error {{is a protected member}}
930 // expected-note@#dr360-bar-using-decl {{declared protected here}}
931 int baz = B().baz();
933 } // namespace dr360
935 // dr362: na
936 // dr363: na
938 namespace dr364 { // dr364: yes
939 struct S {
940 static void f(int);
941 void f(char);
944 void g() {
945 S::f('a'); // expected-error {{call to non-static}}
946 S::f(0);
950 #if "foo" // expected-error {{invalid token}} dr366: yes
951 #endif
953 namespace dr367 { // dr367: yes
954 // FIXME: These diagnostics are terrible. Don't diagnose an ill-formed global
955 // array as being a VLA!
956 int a[true ? throw 0 : 4]; // expected-error 2{{variable length array}}
957 int b[true ? 4 : throw 0];
958 int c[true ? *new int : 4]; // expected-error 2{{variable length array}} expected-note {{read of uninitialized}}
959 int d[true ? 4 : *new int];
960 #if __cplusplus < 201103L
961 // expected-error@-4 2{{variable length array}}
962 // expected-error@-3 2{{variable length array}}
963 #endif
966 namespace dr368 { // dr368: yes
967 template<typename T, T> struct S {}; // expected-note {{here}}
968 template<typename T> int f(S<T, T()> *); // expected-error {{function type}}
969 template<typename T> int g(S<T, (T())> *); // cxx98_17-note {{type 'X'}}
970 // cxx20_23-note@-1 {{candidate function [with T = dr368::X]}}
971 template<typename T> int g(S<T, true ? T() : T()> *); // cxx98_17-note {{type 'X'}}
972 // cxx20_23-note@-1 {{candidate function [with T = dr368::X]}}
973 struct X {};
974 int n = g<X>(0); // cxx98_17-error {{no matching}}
975 // cxx20_23-error@-1 {{call to 'g' is ambiguous}}
978 // dr370: na
980 namespace dr372 { // dr372: no
981 namespace example1 {
982 template<typename T> struct X {
983 protected:
984 typedef T Type; // expected-note 2{{protected}}
986 template<typename T> struct Y {};
988 // FIXME: These two are valid; deriving from T1<T> gives Z1 access to
989 // the protected member T1<T>::Type.
990 template<typename T,
991 template<typename> class T1,
992 template<typename> class T2> struct Z1 :
993 T1<T>,
994 T2<typename T1<T>::Type> {}; // expected-error {{protected}}
996 template<typename T,
997 template<typename> class T1,
998 template<typename> class T2> struct Z2 :
999 T2<typename T1<T>::Type>, // expected-error {{protected}}
1000 T1<T> {};
1002 Z1<int, X, Y> z1; // expected-note {{instantiation of}}
1003 Z2<int, X, Y> z2; // expected-note {{instantiation of}}
1006 namespace example2 {
1007 struct X {
1008 private:
1009 typedef int Type; // expected-note {{private}}
1011 template<typename T> struct A {
1012 typename T::Type t; // expected-error {{private}}
1014 A<X> ax; // expected-note {{instantiation of}}
1017 namespace example3 {
1018 struct A {
1019 protected:
1020 typedef int N; // expected-note 2{{protected}}
1023 template<typename T> struct B {};
1024 template<typename U> struct C : U, B<typename U::N> {}; // expected-error {{protected}}
1025 template<typename U> struct D : B<typename U::N>, U {}; // expected-error {{protected}}
1027 C<A> x; // expected-note {{instantiation of}}
1028 D<A> y; // expected-note {{instantiation of}}
1031 namespace example4 {
1032 class A {
1033 class B {};
1034 friend class X;
1037 struct X : A::B {
1038 A::B mx;
1039 class Y {
1040 A::B my;
1045 // FIXME: This is valid: deriving from A gives D access to A::B
1046 namespace std_example {
1047 class A {
1048 protected:
1049 struct B {}; // expected-note {{here}}
1051 struct D : A::B, A {}; // expected-error {{protected}}
1054 // FIXME: This is valid: deriving from A::B gives access to A::B!
1055 namespace badwolf {
1056 class A {
1057 protected:
1058 struct B; // expected-note {{here}}
1060 struct A::B : A {};
1061 struct C : A::B {}; // expected-error {{protected}}
1065 namespace dr373 { // dr373: 5
1066 namespace X { int dr373; }
1067 struct dr373 { // expected-note {{here}}
1068 void f() {
1069 using namespace dr373::X;
1070 int k = dr373; // expected-error {{does not refer to a value}}
1072 namespace Y = dr373::X;
1073 k = Y::dr373;
1077 struct A { struct B {}; }; // expected-note 2{{here}}
1078 namespace X = A::B; // expected-error {{expected namespace name}}
1079 using namespace A::B; // expected-error {{expected namespace name}}
1082 namespace dr374 { // dr374: yes
1083 namespace N {
1084 template<typename T> void f();
1085 template<typename T> struct A { void f(); };
1087 template<> void N::f<char>() {}
1088 template<> void N::A<char>::f() {}
1089 template<> struct N::A<int> {};
1092 // dr375: dup 345
1093 // dr376: na
1095 namespace dr377 { // dr377: yes
1096 enum E { // expected-error {{enumeration values exceed range of largest integer}}
1097 a = -__LONG_LONG_MAX__ - 1, // expected-error 0-1{{extension}}
1098 b = 2 * (unsigned long long)__LONG_LONG_MAX__ // expected-error 0-2{{extension}}
1102 // dr378: dup 276
1103 // dr379: na
1105 namespace dr381 { // dr381: yes
1106 struct A {
1107 int a;
1109 struct B : virtual A {};
1110 struct C : B {};
1111 struct D : B {};
1112 struct E : public C, public D {};
1113 struct F : public A {};
1114 void f() {
1115 E e;
1116 e.B::a = 0; // expected-error {{ambiguous conversion}}
1117 F f;
1118 f.A::a = 1;
1122 namespace dr382 { // dr382: yes c++11
1123 // FIXME: Should we allow this in C++98 mode?
1124 struct A { typedef int T; };
1125 typename A::T t;
1126 typename dr382::A a;
1127 #if __cplusplus < 201103L
1128 // expected-error@-3 {{occurs outside of a template}}
1129 // expected-error@-3 {{occurs outside of a template}}
1130 #endif
1131 typename A b; // expected-error {{expected a qualified name}}
1134 namespace dr383 { // dr383: yes
1135 struct A { A &operator=(const A&); };
1136 struct B { ~B(); };
1137 union C { C &operator=(const C&); };
1138 union D { ~D(); };
1139 int check[(__is_pod(A) || __is_pod(B) || __is_pod(C) || __is_pod(D)) ? -1 : 1];
1142 namespace dr384 { // dr384: yes
1143 namespace N1 {
1144 template<typename T> struct Base {};
1145 template<typename T> struct X {
1146 struct Y : public Base<T> {
1147 Y operator+(int) const;
1149 Y f(unsigned i) { return Y() + i; }
1153 namespace N2 {
1154 struct Z {};
1155 template<typename T> int *operator+(T, unsigned);
1158 int main() {
1159 N1::X<N2::Z> v;
1160 v.f(0);
1164 namespace dr385 { // dr385: yes
1165 struct A { protected: void f(); };
1166 struct B : A { using A::f; };
1167 struct C : A { void g(B b) { b.f(); } };
1168 void h(B b) { b.f(); }
1170 struct D { int n; }; // expected-note {{member}}
1171 struct E : protected D {}; // expected-note {{protected}}
1172 struct F : E { friend int i(E); };
1173 int i(E e) { return e.n; } // expected-error {{protected member}}
1176 namespace dr387 { // dr387: yes
1177 namespace old {
1178 template<typename T> class number {
1179 number(int); // expected-note 2{{here}}
1180 friend number gcd(number &x, number &y) {}
1183 void g() {
1184 number<double> a(3), b(4); // expected-error 2{{private}}
1185 a = gcd(a, b);
1186 b = gcd(3, 4); // expected-error {{undeclared}}
1190 namespace newer {
1191 template <typename T> class number {
1192 public:
1193 number(int);
1194 friend number gcd(number x, number y) { return 0; }
1197 void g() {
1198 number<double> a(3), b(4);
1199 a = gcd(a, b);
1200 b = gcd(3, 4); // expected-error {{undeclared}}
1205 // FIXME: dr388 needs codegen test
1207 namespace dr389 { // dr389: no
1208 struct S {
1209 typedef struct {} A;
1210 typedef enum {} B;
1211 typedef struct {} const C; // expected-note 0-2{{here}}
1212 typedef enum {} const D; // expected-note 0-1{{here}}
1214 template<typename> struct T {};
1216 struct WithLinkage1 {};
1217 enum WithLinkage2 {};
1218 typedef struct {} *WithLinkage3a, WithLinkage3b;
1219 typedef enum {} WithLinkage4a, *WithLinkage4b;
1220 typedef S::A WithLinkage5;
1221 typedef const S::B WithLinkage6;
1222 typedef int WithLinkage7;
1223 typedef void (*WithLinkage8)(WithLinkage2 WithLinkage1::*, WithLinkage5 *);
1224 typedef T<WithLinkage5> WithLinkage9;
1226 typedef struct {} *WithoutLinkage1; // expected-note 0-1{{here}}
1227 typedef enum {} const WithoutLinkage2; // expected-note 0-1{{here}}
1228 // These two types don't have linkage even though they are externally visible
1229 // and the ODR requires them to be merged across TUs.
1230 typedef S::C WithoutLinkage3;
1231 typedef S::D WithoutLinkage4;
1232 typedef void (*WithoutLinkage5)(int (WithoutLinkage3::*)(char));
1234 #if __cplusplus >= 201103L
1235 // This has linkage even though its template argument does not.
1236 // FIXME: This is probably a defect.
1237 typedef T<WithoutLinkage1> WithLinkage10;
1238 #else
1239 typedef int WithLinkage10; // dummy
1241 typedef T<WithLinkage1> GoodArg1;
1242 typedef T<WithLinkage2> GoodArg2;
1243 typedef T<WithLinkage3a> GoodArg3a;
1244 typedef T<WithLinkage3b> GoodArg3b;
1245 typedef T<WithLinkage4a> GoodArg4a;
1246 typedef T<WithLinkage4b> GoodArg4b;
1247 typedef T<WithLinkage5> GoodArg5;
1248 typedef T<WithLinkage6> GoodArg6;
1249 typedef T<WithLinkage7> GoodArg7;
1250 typedef T<WithLinkage8> GoodArg8;
1251 typedef T<WithLinkage9> GoodArg9;
1253 typedef T<WithoutLinkage1> BadArg1; // expected-error{{template argument uses}}
1254 typedef T<WithoutLinkage2> BadArg2; // expected-error{{template argument uses}}
1255 typedef T<WithoutLinkage3> BadArg3; // expected-error{{template argument uses}}
1256 typedef T<WithoutLinkage4> BadArg4; // expected-error{{template argument uses}}
1257 typedef T<WithoutLinkage5> BadArg5; // expected-error{{template argument uses}}
1258 #endif
1260 extern WithLinkage1 withLinkage1;
1261 extern WithLinkage2 withLinkage2;
1262 extern WithLinkage3a withLinkage3a;
1263 extern WithLinkage3b withLinkage3b;
1264 extern WithLinkage4a withLinkage4a;
1265 extern WithLinkage4b withLinkage4b;
1266 extern WithLinkage5 withLinkage5;
1267 extern WithLinkage6 withLinkage6;
1268 extern WithLinkage7 withLinkage7;
1269 extern WithLinkage8 withLinkage8;
1270 extern WithLinkage9 withLinkage9;
1271 extern WithLinkage10 withLinkage10;
1273 // FIXME: These are all ill-formed.
1274 extern WithoutLinkage1 withoutLinkage1;
1275 extern WithoutLinkage2 withoutLinkage2;
1276 extern WithoutLinkage3 withoutLinkage3;
1277 extern WithoutLinkage4 withoutLinkage4;
1278 extern WithoutLinkage5 withoutLinkage5;
1280 // OK, extern "C".
1281 extern "C" {
1282 extern WithoutLinkage1 dr389_withoutLinkage1;
1283 extern WithoutLinkage2 dr389_withoutLinkage2;
1284 extern WithoutLinkage3 dr389_withoutLinkage3;
1285 extern WithoutLinkage4 dr389_withoutLinkage4;
1286 extern WithoutLinkage5 dr389_withoutLinkage5;
1289 // OK, defined.
1290 WithoutLinkage1 withoutLinkageDef1;
1291 WithoutLinkage2 withoutLinkageDef2 = WithoutLinkage2();
1292 WithoutLinkage3 withoutLinkageDef3 = {};
1293 WithoutLinkage4 withoutLinkageDef4 = WithoutLinkage4();
1294 WithoutLinkage5 withoutLinkageDef5;
1296 void use(const void *);
1297 void use_all() {
1298 use(&withLinkage1); use(&withLinkage2); use(&withLinkage3a); use(&withLinkage3b);
1299 use(&withLinkage4a); use(&withLinkage4b); use(&withLinkage5); use(&withLinkage6);
1300 use(&withLinkage7); use(&withLinkage8); use(&withLinkage9); use(&withLinkage10);
1302 use(&withoutLinkage1); use(&withoutLinkage2); use(&withoutLinkage3);
1303 use(&withoutLinkage4); use(&withoutLinkage5);
1305 use(&dr389_withoutLinkage1); use(&dr389_withoutLinkage2);
1306 use(&dr389_withoutLinkage3); use(&dr389_withoutLinkage4);
1307 use(&dr389_withoutLinkage5);
1309 use(&withoutLinkageDef1); use(&withoutLinkageDef2); use(&withoutLinkageDef3);
1310 use(&withoutLinkageDef4); use(&withoutLinkageDef5);
1313 void local() {
1314 // FIXME: This is ill-formed.
1315 extern WithoutLinkage1 withoutLinkageLocal;
1319 namespace dr390 { // dr390: yes
1320 template<typename T>
1321 struct A {
1322 A() { f(); } // expected-warning {{call to pure virt}}
1323 virtual void f() = 0; // expected-note {{here}}
1324 virtual ~A() = 0;
1326 template<typename T> A<T>::~A() { T::error; } // expected-error {{cannot be used prior to}}
1327 template<typename T> void A<T>::f() { T::error; } // ok, not odr-used
1328 struct B : A<int> { // expected-note 2{{in instantiation of}}
1329 void f() {}
1330 } b;
1333 namespace dr391 { // dr391: yes c++11
1334 // FIXME: Should this apply to C++98 too?
1335 class A { A(const A&); }; // expected-note 0-1{{here}}
1336 A fa();
1337 const A &a = fa();
1338 #if __cplusplus < 201103L
1339 // expected-error@-2 {{C++98 requires an accessible copy constructor}}
1340 #endif
1342 struct B { B(const B&) = delete; }; // expected-error 0-1{{extension}} expected-note 0-1{{here}}
1343 B fb();
1344 const B &b = fb();
1345 #if __cplusplus < 201103L
1346 // expected-error@-2 {{deleted}}
1347 #endif
1349 template<typename T>
1350 struct C {
1351 C(const C&) { T::error; }
1353 C<int> fc();
1354 const C<int> &c = fc();
1357 // dr392 FIXME write codegen test
1358 // dr394: na
1360 namespace dr395 { // dr395: yes
1361 struct S {
1362 template <typename T, int N>(&operator T())[N]; // expected-error {{cannot specify any part of a return type}}
1363 template <typename T, int N> operator(T (&)[N])(); // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error +{{}}
1364 template <typename T> operator T *() const { return 0; }
1365 template <typename T, typename U> operator T U::*() const { return 0; }
1366 template <typename T, typename U> operator T (U::*)()() const { return 0; } // expected-error +{{}}
1369 struct null1_t {
1370 template <class T, class U> struct ptr_mem_fun_t {
1371 typedef T (U::*type)();
1374 template <class T, class U>
1375 operator typename ptr_mem_fun_t<T, U>::type() const { // expected-note {{couldn't infer}}
1376 return 0;
1378 } null1;
1379 int (S::*p)() = null1; // expected-error {{no viable conversion}}
1381 template <typename T> using id = T; // expected-error 0-1{{extension}}
1383 struct T {
1384 template <typename T, int N> operator id<T[N]> &();
1385 template <typename T, typename U> operator id<T (U::*)()>() const;
1388 struct null2_t {
1389 template<class T, class U> using ptr_mem_fun_t = T (U::*)(); // expected-error 0-1{{extension}}
1390 template<class T, class U> operator ptr_mem_fun_t<T, U>() const { return 0; };
1391 } null2;
1392 int (S::*q)() = null2;
1395 namespace dr396 { // dr396: yes
1396 void f() {
1397 auto int a(); // expected-error {{storage class on function}}
1398 int (i); // expected-note {{previous}}
1399 auto int (i); // expected-error {{redefinition}}
1400 #if __cplusplus >= 201103L
1401 // expected-error@-4 {{'auto' storage class}} expected-error@-2 {{'auto' storage class}}
1402 #endif
1406 // dr397: sup 1823
1408 namespace dr398 { // dr398: yes
1409 namespace example1 {
1410 struct S {
1411 static int const I = 42;
1413 template <int N> struct X {};
1414 template <typename T> void f(X<T::I> *) {}
1415 template <typename T> void f(X<T::J> *) {}
1416 void foo() { f<S>(0); }
1419 namespace example2 {
1420 template <int I> struct X {};
1421 template <template <class T> class> struct Z {};
1422 template <class T> void f(typename T::Y *) {} // expected-note 2{{substitution failure}}
1423 template <class T> void g(X<T::N> *) {} // expected-note {{substitution failure}}
1424 template <class T> void h(Z<T::template TT> *) {} // expected-note {{substitution failure}}
1425 struct A {};
1426 struct B {
1427 int Y;
1429 struct C {
1430 typedef int N;
1432 struct D {
1433 typedef int TT;
1436 void test() {
1437 f<A>(0); // expected-error {{no matching function}}
1438 f<B>(0); // expected-error {{no matching function}}
1439 g<C>(0); // expected-error {{no matching function}}
1440 h<D>(0); // expected-error {{no matching function}}
1445 namespace dr399 { // dr399: 11
1446 // NB: reuse dr244 test
1447 struct B {}; // expected-note {{type 'dr399::B' found by destructor name lookup}}
1448 struct D : B {};
1450 D D_object;
1451 typedef B B_alias;
1452 B* B_ptr = &D_object;
1454 void f() {
1455 D_object.~B(); // expected-error {{does not match the type 'D' of the object being destroyed}}
1456 D_object.B::~B();
1457 D_object.D::~B(); // FIXME: Missing diagnostic for this.
1458 B_ptr->~B();
1459 B_ptr->~B_alias();
1460 B_ptr->B_alias::~B();
1461 B_ptr->B_alias::~B_alias();
1462 B_ptr->dr399::~B(); // expected-error {{refers to a member in namespace}}
1463 B_ptr->dr399::~B_alias(); // expected-error {{refers to a member in namespace}}
1466 template<typename T, typename U>
1467 void f(T *B_ptr, U D_object) {
1468 D_object.~B(); // FIXME: Missing diagnostic for this.
1469 D_object.B::~B();
1470 D_object.D::~B(); // FIXME: Missing diagnostic for this.
1471 B_ptr->~B();
1472 B_ptr->~B_alias();
1473 B_ptr->B_alias::~B();
1474 B_ptr->B_alias::~B_alias();
1475 B_ptr->dr399::~B(); // expected-error {{does not refer to a type name}}
1476 B_ptr->dr399::~B_alias(); // expected-error {{does not refer to a type name}}
1478 template void f<B, D>(B*, D);
1480 namespace N {
1481 template<typename T> struct E {};
1482 typedef E<int> F;
1484 void g(N::F f) {
1485 typedef N::F G; // expected-note {{found by destructor name lookup}}
1486 f.~G();
1487 f.G::~E(); // expected-error {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
1488 f.G::~F(); // expected-error {{undeclared identifier 'F' in destructor name}}
1489 f.G::~G();
1490 // This is technically ill-formed; E is looked up in 'N::' and names the
1491 // class template, not the injected-class-name of the class. But that's
1492 // probably a bug in the standard.
1493 f.N::F::~E(); // expected-error {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
1494 // This is valid; we look up the second F in the same scope in which we
1495 // found the first one, that is, 'N::'.
1496 f.N::F::~F();
1497 // This is technically ill-formed; G is looked up in 'N::' and is not found.
1498 // Rejecting this seems correct, but most compilers accept, so we do also.
1499 f.N::F::~G(); // expected-error {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}
1502 // Bizarrely, compilers perform lookup in the scope for qualified destructor
1503 // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
1504 // this.
1505 namespace QualifiedLookupInScope {
1506 namespace N {
1507 template <typename> struct S { struct Inner {}; };
1509 template <typename U> void f(typename N::S<U>::Inner *p) {
1510 typedef typename N::S<U>::Inner T;
1511 p->::dr399::QualifiedLookupInScope::N::S<U>::Inner::~T(); // expected-error {{no type named 'T' in}}
1513 template void f<int>(N::S<int>::Inner *); // expected-note {{instantiation of}}
1515 template <typename U> void g(U *p) {
1516 typedef U T;
1517 p->T::~T();
1518 p->U::~T();
1519 p->::dr399::QualifiedLookupInScope::N::S<int>::Inner::~T(); // expected-error {{'T' does not refer to a type name}}
1521 template void g(N::S<int>::Inner *);