blob: 3971881a6b8d16ccc05b7537a59cb16b8a1a9b15 [file] [log] [blame]
Richard Smithd6537012012-11-15 00:31:27 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %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
David Blaikie91ec7892011-12-16 16:03:09 +000022void f(A* a, Foo *f, int *i, double *d, int ii) {
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
David Blaikie91ec7892011-12-16 16:03:09 +000049 ii->~Integer(); // expected-error{{member reference type 'int' is not a pointer; maybe you meant to use '.'?}}
50 ii.~Integer();
51
John McCall81e317a2010-06-11 17:36:40 +000052 cv_test(a);
53 cv_test(f);
54 cv_test(i);
55 cv_test(d);
Anders Carlsson2cf738f2009-08-26 19:22:42 +000056}
Douglas Gregora78c5c32009-09-04 18:29:40 +000057
John McCall81e317a2010-06-11 17:36:40 +000058
Douglas Gregora78c5c32009-09-04 18:29:40 +000059typedef int Integer;
60
61void destroy_without_call(int *ip) {
Stephen Hines0e2c34f2015-03-23 12:09:02 -070062 ip->~Integer; // expected-error{{reference to pseudo-destructor must be called}}
63}
64
65void paren_destroy_with_call(int *ip) {
66 (ip->~Integer)();
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000067}
Douglas Gregorf6e6fc82009-11-20 22:03:38 +000068
69// PR5530
70namespace N1 {
71 class X0 { };
72}
73
74void test_X0(N1::X0 &x0) {
75 x0.~X0();
76}
John McCall81e317a2010-06-11 17:36:40 +000077
Douglas Gregor6b18e742011-11-09 02:19:47 +000078namespace PR11339 {
79 template<class T>
80 void destroy(T* p) {
81 p->~T(); // ok
82 p->~oops(); // expected-error{{expected the class name after '~' to name a destructor}}
83 }
84
85 template void destroy(int*); // expected-note{{in instantiation of function template specialization}}
86}
Richard Smithd6537012012-11-15 00:31:27 +000087
88template<typename T> using Id = T;
89void AliasTemplate(int *p) {
90 p->~Id<int>();
91}