1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2*f4a2713aSLionel Sambuc struct A {};
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc enum Foo { F };
5*f4a2713aSLionel Sambuc typedef Foo Bar; // expected-note{{type 'Bar' (aka 'Foo') is declared here}}
6*f4a2713aSLionel Sambuc
7*f4a2713aSLionel Sambuc typedef int Integer;
8*f4a2713aSLionel Sambuc typedef double Double;
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambuc void g();
11*f4a2713aSLionel Sambuc
12*f4a2713aSLionel Sambuc namespace N {
13*f4a2713aSLionel Sambuc typedef Foo Wibble;
14*f4a2713aSLionel Sambuc typedef int OtherInteger;
15*f4a2713aSLionel Sambuc }
16*f4a2713aSLionel Sambuc
17*f4a2713aSLionel Sambuc template <typename T>
cv_test(const volatile T * cvt)18*f4a2713aSLionel Sambuc void cv_test(const volatile T* cvt) {
19*f4a2713aSLionel Sambuc cvt->T::~T(); // no-warning
20*f4a2713aSLionel Sambuc }
21*f4a2713aSLionel Sambuc
f(A * a,Foo * f,int * i,double * d,int ii)22*f4a2713aSLionel Sambuc void f(A* a, Foo *f, int *i, double *d, int ii) {
23*f4a2713aSLionel Sambuc a->~A();
24*f4a2713aSLionel Sambuc a->A::~A();
25*f4a2713aSLionel Sambuc
26*f4a2713aSLionel Sambuc a->~foo(); // expected-error{{identifier 'foo' in object destruction expression does not name a type}}
27*f4a2713aSLionel Sambuc
28*f4a2713aSLionel Sambuc a->~Bar(); // expected-error{{destructor type 'Bar' (aka 'Foo') in object destruction expression does not match the type 'A' of the object being destroyed}}
29*f4a2713aSLionel Sambuc
30*f4a2713aSLionel Sambuc f->~Bar();
31*f4a2713aSLionel Sambuc f->~Foo();
32*f4a2713aSLionel Sambuc i->~Bar(); // expected-error{{does not match}}
33*f4a2713aSLionel Sambuc
34*f4a2713aSLionel Sambuc g().~Bar(); // expected-error{{non-scalar}}
35*f4a2713aSLionel Sambuc
36*f4a2713aSLionel Sambuc f->::~Bar();
37*f4a2713aSLionel Sambuc f->N::~Wibble(); // FIXME: technically, Wibble isn't a class-name
38*f4a2713aSLionel Sambuc
39*f4a2713aSLionel Sambuc f->::~Bar(17, 42); // expected-error{{cannot have any arguments}}
40*f4a2713aSLionel Sambuc
41*f4a2713aSLionel Sambuc i->~Integer();
42*f4a2713aSLionel Sambuc i->Integer::~Integer();
43*f4a2713aSLionel Sambuc i->N::~OtherInteger();
44*f4a2713aSLionel Sambuc i->N::OtherInteger::~OtherInteger();
45*f4a2713aSLionel Sambuc i->N::OtherInteger::~Integer(); // expected-error{{'Integer' does not refer to a type name in pseudo-destructor expression; expected the name of type 'int'}}
46*f4a2713aSLionel Sambuc i->N::~Integer(); // expected-error{{'Integer' does not refer to a type name in pseudo-destructor expression; expected the name of type 'int'}}
47*f4a2713aSLionel Sambuc i->Integer::~Double(); // expected-error{{the type of object expression ('int') does not match the type being destroyed ('Double' (aka 'double')) in pseudo-destructor expression}}
48*f4a2713aSLionel Sambuc
49*f4a2713aSLionel Sambuc ii->~Integer(); // expected-error{{member reference type 'int' is not a pointer; maybe you meant to use '.'?}}
50*f4a2713aSLionel Sambuc ii.~Integer();
51*f4a2713aSLionel Sambuc
52*f4a2713aSLionel Sambuc cv_test(a);
53*f4a2713aSLionel Sambuc cv_test(f);
54*f4a2713aSLionel Sambuc cv_test(i);
55*f4a2713aSLionel Sambuc cv_test(d);
56*f4a2713aSLionel Sambuc }
57*f4a2713aSLionel Sambuc
58*f4a2713aSLionel Sambuc
59*f4a2713aSLionel Sambuc typedef int Integer;
60*f4a2713aSLionel Sambuc
destroy_without_call(int * ip)61*f4a2713aSLionel Sambuc void destroy_without_call(int *ip) {
62*f4a2713aSLionel Sambuc ip->~Integer; // expected-error{{called immediately}}
63*f4a2713aSLionel Sambuc }
64*f4a2713aSLionel Sambuc
65*f4a2713aSLionel Sambuc // PR5530
66*f4a2713aSLionel Sambuc namespace N1 {
67*f4a2713aSLionel Sambuc class X0 { };
68*f4a2713aSLionel Sambuc }
69*f4a2713aSLionel Sambuc
test_X0(N1::X0 & x0)70*f4a2713aSLionel Sambuc void test_X0(N1::X0 &x0) {
71*f4a2713aSLionel Sambuc x0.~X0();
72*f4a2713aSLionel Sambuc }
73*f4a2713aSLionel Sambuc
74*f4a2713aSLionel Sambuc namespace PR11339 {
75*f4a2713aSLionel Sambuc template<class T>
destroy(T * p)76*f4a2713aSLionel Sambuc void destroy(T* p) {
77*f4a2713aSLionel Sambuc p->~T(); // ok
78*f4a2713aSLionel Sambuc p->~oops(); // expected-error{{expected the class name after '~' to name a destructor}}
79*f4a2713aSLionel Sambuc }
80*f4a2713aSLionel Sambuc
81*f4a2713aSLionel Sambuc template void destroy(int*); // expected-note{{in instantiation of function template specialization}}
82*f4a2713aSLionel Sambuc }
83*f4a2713aSLionel Sambuc
84*f4a2713aSLionel Sambuc template<typename T> using Id = T;
AliasTemplate(int * p)85*f4a2713aSLionel Sambuc void AliasTemplate(int *p) {
86*f4a2713aSLionel Sambuc p->~Id<int>();
87*f4a2713aSLionel Sambuc }
88