1 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2
3 // PR10127/N3031
4 struct A { ~A(); };
5 struct B {};
6 template<typename T>
b(const T * x,const A * y)7 void b(const T *x, const A *y) {
8 x->~decltype(T())();
9 x->~decltype(*x)(); // expected-error{{the type of object expression ('const int') does not match the type being destroyed ('decltype(*x)' (aka 'const int &')) in pseudo-destructor expression}} \
10 expected-error{{no member named '~const struct A &' in 'A'}}
11 x->~decltype(int())(); // expected-error{{no member named '~int' in 'A'}}
12
13 y->~decltype(*y)(); // expected-error{{destructor type 'decltype(*y)' (aka 'const A &') in object destruction expression does not match the type 'const A' of the object being destroyed}}
14 y->~decltype(T())(); // expected-error{{destructor type 'decltype(T())' in object destruction expression does not match the type 'const A' of the object being destroyed}}
15 y->~decltype(A())();
16 }
17 template void b(const int*, const A*); // expected-note{{in instantiation of function template specialization 'b<int>' requested here}}
18 template void b(const A*,const A*); // expected-note{{in instantiation of function template specialization 'b<A>' requested here}}
a(const A * x,int i,int * pi)19 void a(const A *x, int i, int *pi) {
20 x->~decltype(A())();
21 x->~decltype(*x)(); // expected-error{{destructor type 'decltype(*x)' (aka 'const A &') in object destruction expression does not match the type 'const A' of the object being destroyed}}
22 x->~decltype()(); // expected-error{{expected expression}}
23 x->~decltype(B())(); // expected-error{{destructor type 'decltype(B())' (aka 'B') in object destruction expression does not match the type 'const A' of the object being destroyed}}
24 x->~decltype(x)(); // expected-error{{destructor type 'decltype(x)' (aka 'const A *') in object destruction expression does not match the type 'const A' of the object being destroyed}}
25 // this last one could be better, mentioning that the nested-name-specifier could be removed or a type name after the ~
26 x->::A::~decltype(*x)(); // expected-error{{expected a class name after '~' to name a destructor}}
27 y->~decltype(A())(); // expected-error{{use of undeclared identifier 'y'}}
28
29 typedef int *intp;
30 i->~decltype(int())(); // expected-error{{member reference type 'int' is not a pointer; maybe you meant to use '.'?}}
31 i.~decltype(int())();
32 i->~decltype(intp())(); // expected-error{{member reference type 'int' is not a pointer; maybe you meant to use '.'?}} \
33 expected-error{{the type of object expression ('int') does not match the type being destroyed ('decltype(intp())' (aka 'int *')) in pseudo-destructor expression}}
34 i.~decltype(intp())(); // expected-error{{the type of object expression ('int') does not match the type being destroyed ('decltype(intp())' (aka 'int *')) in pseudo-destructor expression}}
35 pi->~decltype(int())();
36 pi.~decltype(int())(); // expected-error{{the type of object expression ('int *') does not match the type being destroyed ('decltype(int())' (aka 'int')) in pseudo-destructor expression}}
37 pi.~decltype(intp())();
38 pi->~decltype(intp())(); // expected-error{{the type of object expression ('int') does not match the type being destroyed ('decltype(intp())' (aka 'int *')) in pseudo-destructor expression}}
39 }
40