blob: 30d9faac2e284a0b58a6281ea632ad5b61d0c959 [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 };
5typedef Foo Bar;
6
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
26 a->~foo(); // expected-error{{identifier 'foo' in pseudo-destructor expression does not name a type}}
Douglas Gregora71d8192009-09-04 17:36:40 +000027
Douglas Gregor124b8782010-02-16 19:09:40 +000028 // FIXME: the diagnostic below isn't wonderful
29 a->~Bar(); // expected-error{{does not name a type}}
Douglas Gregora71d8192009-09-04 17:36:40 +000030
31 f->~Bar();
32 f->~Foo();
33 i->~Bar(); // expected-error{{does not match}}
34
35 g().~Bar(); // expected-error{{non-scalar}}
36
37 f->::~Bar();
Douglas Gregor93649fd2010-02-23 00:15:22 +000038 f->N::~Wibble(); // FIXME: technically, Wibble isn't a class-name
Douglas Gregora71d8192009-09-04 17:36:40 +000039
40 f->::~Bar(17, 42); // expected-error{{cannot have any arguments}}
Douglas Gregorb10cd042010-02-21 18:36:56 +000041
42 i->~Integer();
43 i->Integer::~Integer();
Douglas Gregor77549082010-02-24 21:29:12 +000044 i->N::~OtherInteger();
45 i->N::OtherInteger::~OtherInteger();
46 i->N::OtherInteger::~Integer(); // expected-error{{'Integer' does not refer to a type name in pseudo-destructor expression; expected the name of type 'int'}}
47 i->N::~Integer(); // expected-error{{'Integer' does not refer to a type name in pseudo-destructor expression; expected the name of type 'int'}}
48 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 +000049
50 cv_test(a);
51 cv_test(f);
52 cv_test(i);
53 cv_test(d);
Anders Carlsson2cf738f2009-08-26 19:22:42 +000054}
Douglas Gregora78c5c32009-09-04 18:29:40 +000055
John McCall81e317a2010-06-11 17:36:40 +000056
Douglas Gregora78c5c32009-09-04 18:29:40 +000057typedef int Integer;
58
59void destroy_without_call(int *ip) {
60 ip->~Integer; // expected-error{{called immediately}}
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000061}
Douglas Gregorf6e6fc82009-11-20 22:03:38 +000062
63// PR5530
64namespace N1 {
65 class X0 { };
66}
67
68void test_X0(N1::X0 &x0) {
69 x0.~X0();
70}
John McCall81e317a2010-06-11 17:36:40 +000071