blob: 95363e5f6bae755b92d4028f0b92d17629acef29 [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) {
62 ip->~Integer; // expected-error{{called immediately}}
Daniel Dunbar4fcfde42009-11-08 01:45:36 +000063}
Douglas Gregorf6e6fc82009-11-20 22:03:38 +000064
65// PR5530
66namespace N1 {
67 class X0 { };
68}
69
70void test_X0(N1::X0 &x0) {
71 x0.~X0();
72}
John McCall81e317a2010-06-11 17:36:40 +000073
Douglas Gregor6b18e742011-11-09 02:19:47 +000074namespace PR11339 {
75 template<class T>
76 void destroy(T* p) {
77 p->~T(); // ok
78 p->~oops(); // expected-error{{expected the class name after '~' to name a destructor}}
79 }
80
81 template void destroy(int*); // expected-note{{in instantiation of function template specialization}}
82}
Richard Smithd6537012012-11-15 00:31:27 +000083
84template<typename T> using Id = T;
85void AliasTemplate(int *p) {
86 p->~Id<int>();
87}