blob: bd3984817512613c3187b7f428ff1a71f9e84ca1 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Anders Carlsson2cf738f2009-08-26 19:22:42 +00002struct A {};
3
4enum Foo { F };
Douglas Gregor7ec18732011-03-04 22:32:08 +00005typedef Foo Bar; // expected-note{{type 'Bar' (aka 'Foo') is declared here}}
Anders Carlsson2cf738f2009-08-26 19:22:42 +00006
Douglas Gregora71d8192009-09-04 17:36:40 +00007typedef int Integer;
Douglas Gregorb10cd042010-02-21 18:36:56 +00008typedef double Double;
Douglas Gregora71d8192009-09-04 17:36:40 +00009
10void g();
11
12namespace N {
13 typedef Foo Wibble;
Douglas Gregor77549082010-02-24 21:29:12 +000014 typedef int OtherInteger;
Douglas Gregora71d8192009-09-04 17:36:40 +000015}
16
John McCall81e317a2010-06-11 17:36:40 +000017template <typename T>
18void cv_test(const volatile T* cvt) {
19 cvt->T::~T(); // no-warning
20}
21
Douglas Gregorb10cd042010-02-21 18:36:56 +000022void f(A* a, Foo *f, int *i, double *d) {
Anders Carlsson2cf738f2009-08-26 19:22:42 +000023 a->~A();
24 a->A::~A();
25
Douglas Gregor7ec18732011-03-04 22:32:08 +000026 a->~foo(); // expected-error{{identifier 'foo' in object destruction expression does not name a type}}
Douglas Gregora71d8192009-09-04 17:36:40 +000027
Douglas Gregor7ec18732011-03-04 22:32:08 +000028 a->~Bar(); // expected-error{{destructor type 'Bar' (aka 'Foo') in object destruction expression does not match the type 'A' of the object being destroyed}}
Douglas Gregora71d8192009-09-04 17:36:40 +000029
30 f->~Bar();
31 f->~Foo();
32 i->~Bar(); // expected-error{{does not match}}
33
34 g().~Bar(); // expected-error{{non-scalar}}
35
36 f->::~Bar();
Douglas Gregor93649fd2010-02-23 00:15:22 +000037 f->N::~Wibble(); // FIXME: technically, Wibble isn't a class-name
Douglas Gregora71d8192009-09-04 17:36:40 +000038
39 f->::~Bar(17, 42); // expected-error{{cannot have any arguments}}
Douglas Gregorb10cd042010-02-21 18:36:56 +000040
41 i->~Integer();
42 i->Integer::~Integer();
Douglas Gregor77549082010-02-24 21:29:12 +000043 i->N::~OtherInteger();
44 i->N::OtherInteger::~OtherInteger();
45 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 i->N::~Integer(); // expected-error{{'Integer' does not refer to a type name in pseudo-destructor expression; expected the name of type 'int'}}
47 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}}
John McCall81e317a2010-06-11 17:36:40 +000048
49 cv_test(a);
50 cv_test(f);
51 cv_test(i);
52 cv_test(d);
Anders Carlsson2cf738f2009-08-26 19:22:42 +000053}
Douglas Gregora78c5c32009-09-04 18:29:40 +000054
John McCall81e317a2010-06-11 17:36:40 +000055
Douglas Gregora78c5c32009-09-04 18:29:40 +000056typedef int Integer;
57
58void destroy_without_call(int *ip) {
59 ip->~Integer; // expected-error{{called immediately}}
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000060}
Douglas Gregorf6e6fc82009-11-20 22:03:38 +000061
62// PR5530
63namespace N1 {
64 class X0 { };
65}
66
67void test_X0(N1::X0 &x0) {
68 x0.~X0();
69}
John McCall81e317a2010-06-11 17:36:40 +000070
Douglas Gregor6b18e742011-11-09 02:19:47 +000071namespace PR11339 {
72 template<class T>
73 void destroy(T* p) {
74 p->~T(); // ok
75 p->~oops(); // expected-error{{expected the class name after '~' to name a destructor}}
76 }
77
78 template void destroy(int*); // expected-note{{in instantiation of function template specialization}}
79}