Richard Smith | d653701 | 2012-11-15 00:31:27 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
Anders Carlsson | 2cf738f | 2009-08-26 19:22:42 +0000 | [diff] [blame] | 2 | struct A {}; |
| 3 | |
| 4 | enum Foo { F }; |
Douglas Gregor | 7ec1873 | 2011-03-04 22:32:08 +0000 | [diff] [blame] | 5 | typedef Foo Bar; // expected-note{{type 'Bar' (aka 'Foo') is declared here}} |
Anders Carlsson | 2cf738f | 2009-08-26 19:22:42 +0000 | [diff] [blame] | 6 | |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 7 | typedef int Integer; |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 8 | typedef double Double; |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 9 | |
| 10 | void g(); |
| 11 | |
| 12 | namespace N { |
| 13 | typedef Foo Wibble; |
Douglas Gregor | 7754908 | 2010-02-24 21:29:12 +0000 | [diff] [blame] | 14 | typedef int OtherInteger; |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 15 | } |
| 16 | |
John McCall | 81e317a | 2010-06-11 17:36:40 +0000 | [diff] [blame] | 17 | template <typename T> |
| 18 | void cv_test(const volatile T* cvt) { |
| 19 | cvt->T::~T(); // no-warning |
| 20 | } |
| 21 | |
David Blaikie | 91ec789 | 2011-12-16 16:03:09 +0000 | [diff] [blame] | 22 | void f(A* a, Foo *f, int *i, double *d, int ii) { |
Anders Carlsson | 2cf738f | 2009-08-26 19:22:42 +0000 | [diff] [blame] | 23 | a->~A(); |
| 24 | a->A::~A(); |
| 25 | |
Douglas Gregor | 7ec1873 | 2011-03-04 22:32:08 +0000 | [diff] [blame] | 26 | a->~foo(); // expected-error{{identifier 'foo' in object destruction expression does not name a type}} |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 27 | |
Douglas Gregor | 7ec1873 | 2011-03-04 22:32:08 +0000 | [diff] [blame] | 28 | 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 Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 29 | |
| 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 Gregor | 93649fd | 2010-02-23 00:15:22 +0000 | [diff] [blame] | 37 | f->N::~Wibble(); // FIXME: technically, Wibble isn't a class-name |
Douglas Gregor | a71d819 | 2009-09-04 17:36:40 +0000 | [diff] [blame] | 38 | |
| 39 | f->::~Bar(17, 42); // expected-error{{cannot have any arguments}} |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 40 | |
| 41 | i->~Integer(); |
| 42 | i->Integer::~Integer(); |
Douglas Gregor | 7754908 | 2010-02-24 21:29:12 +0000 | [diff] [blame] | 43 | 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 McCall | 81e317a | 2010-06-11 17:36:40 +0000 | [diff] [blame] | 48 | |
David Blaikie | 91ec789 | 2011-12-16 16:03:09 +0000 | [diff] [blame] | 49 | ii->~Integer(); // expected-error{{member reference type 'int' is not a pointer; maybe you meant to use '.'?}} |
| 50 | ii.~Integer(); |
| 51 | |
John McCall | 81e317a | 2010-06-11 17:36:40 +0000 | [diff] [blame] | 52 | cv_test(a); |
| 53 | cv_test(f); |
| 54 | cv_test(i); |
| 55 | cv_test(d); |
Anders Carlsson | 2cf738f | 2009-08-26 19:22:42 +0000 | [diff] [blame] | 56 | } |
Douglas Gregor | a78c5c3 | 2009-09-04 18:29:40 +0000 | [diff] [blame] | 57 | |
John McCall | 81e317a | 2010-06-11 17:36:40 +0000 | [diff] [blame] | 58 | |
Douglas Gregor | a78c5c3 | 2009-09-04 18:29:40 +0000 | [diff] [blame] | 59 | typedef int Integer; |
| 60 | |
| 61 | void destroy_without_call(int *ip) { |
| 62 | ip->~Integer; // expected-error{{called immediately}} |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 63 | } |
Douglas Gregor | f6e6fc8 | 2009-11-20 22:03:38 +0000 | [diff] [blame] | 64 | |
| 65 | // PR5530 |
| 66 | namespace N1 { |
| 67 | class X0 { }; |
| 68 | } |
| 69 | |
| 70 | void test_X0(N1::X0 &x0) { |
| 71 | x0.~X0(); |
| 72 | } |
John McCall | 81e317a | 2010-06-11 17:36:40 +0000 | [diff] [blame] | 73 | |
Douglas Gregor | 6b18e74 | 2011-11-09 02:19:47 +0000 | [diff] [blame] | 74 | namespace 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 Smith | d653701 | 2012-11-15 00:31:27 +0000 | [diff] [blame] | 83 | |
| 84 | template<typename T> using Id = T; |
| 85 | void AliasTemplate(int *p) { |
| 86 | p->~Id<int>(); |
| 87 | } |