1ecd8a94aSDavid Blaikie // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2ecd8a94aSDavid Blaikie
3ecd8a94aSDavid Blaikie // PR10127/N3031
4ecd8a94aSDavid Blaikie struct A { ~A(); };
5ecd8a94aSDavid Blaikie struct B {};
6ecd8a94aSDavid Blaikie template<typename T>
b(const T * x,const A * y)7ecd8a94aSDavid Blaikie void b(const T *x, const A *y) {
81d578782SDavid Blaikie x->~decltype(T())();
91d578782SDavid Blaikie 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}} \
10e81daee2SRichard Smith expected-error{{no member named '~const A &' in 'A'}}
111d578782SDavid Blaikie x->~decltype(int())(); // expected-error{{no member named '~int' in 'A'}}
12ecd8a94aSDavid Blaikie
13ecd8a94aSDavid Blaikie 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}}
14ecd8a94aSDavid Blaikie 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}}
15ecd8a94aSDavid Blaikie y->~decltype(A())();
16ecd8a94aSDavid Blaikie }
171d578782SDavid Blaikie template void b(const int*, const A*); // expected-note{{in instantiation of function template specialization 'b<int>' requested here}}
181d578782SDavid Blaikie 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)191d578782SDavid Blaikie void a(const A *x, int i, int *pi) {
20ecd8a94aSDavid Blaikie x->~decltype(A())();
21ecd8a94aSDavid Blaikie 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}}
22ecd8a94aSDavid Blaikie x->~decltype()(); // expected-error{{expected expression}}
23ecd8a94aSDavid Blaikie 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}}
24ecd8a94aSDavid Blaikie 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}}
25ecd8a94aSDavid Blaikie // this last one could be better, mentioning that the nested-name-specifier could be removed or a type name after the ~
26ecd8a94aSDavid Blaikie x->::A::~decltype(*x)(); // expected-error{{expected a class name after '~' to name a destructor}}
2708608f67SDavid Blaikie y->~decltype(A())(); // expected-error{{use of undeclared identifier 'y'}}
281d578782SDavid Blaikie
291d578782SDavid Blaikie typedef int *intp;
306e11073bSEric Christopher i->~decltype(int())(); // expected-error{{member reference type 'int' is not a pointer; did you mean to use '.'?}}
311d578782SDavid Blaikie i.~decltype(int())();
326e11073bSEric Christopher i->~decltype(intp())(); // expected-error{{member reference type 'int' is not a pointer; did you mean to use '.'?}} \
331d578782SDavid Blaikie expected-error{{the type of object expression ('int') does not match the type being destroyed ('decltype(intp())' (aka 'int *')) in pseudo-destructor expression}}
341d578782SDavid Blaikie 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}}
351d578782SDavid Blaikie pi->~decltype(int())();
36*56fb6fefSAlex Lorenz pi.~decltype(int())(); // expected-error{{member reference type 'int *' is a pointer; did you mean to use '->'?}}
371d578782SDavid Blaikie pi.~decltype(intp())();
381d578782SDavid Blaikie 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}}
39ecd8a94aSDavid Blaikie }
40