Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %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 | |
Douglas Gregor | b10cd04 | 2010-02-21 18:36:56 +0000 | [diff] [blame] | 22 | void f(A* a, Foo *f, int *i, double *d) { |
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 | |
| 49 | cv_test(a); |
| 50 | cv_test(f); |
| 51 | cv_test(i); |
| 52 | cv_test(d); |
Anders Carlsson | 2cf738f | 2009-08-26 19:22:42 +0000 | [diff] [blame] | 53 | } |
Douglas Gregor | a78c5c3 | 2009-09-04 18:29:40 +0000 | [diff] [blame] | 54 | |
John McCall | 81e317a | 2010-06-11 17:36:40 +0000 | [diff] [blame] | 55 | |
Douglas Gregor | a78c5c3 | 2009-09-04 18:29:40 +0000 | [diff] [blame] | 56 | typedef int Integer; |
| 57 | |
| 58 | void destroy_without_call(int *ip) { |
| 59 | ip->~Integer; // expected-error{{called immediately}} |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 60 | } |
Douglas Gregor | f6e6fc8 | 2009-11-20 22:03:38 +0000 | [diff] [blame] | 61 | |
| 62 | // PR5530 |
| 63 | namespace N1 { |
| 64 | class X0 { }; |
| 65 | } |
| 66 | |
| 67 | void test_X0(N1::X0 &x0) { |
| 68 | x0.~X0(); |
| 69 | } |
John McCall | 81e317a | 2010-06-11 17:36:40 +0000 | [diff] [blame] | 70 | |
Douglas Gregor | 6b18e74 | 2011-11-09 02:19:47 +0000 | [diff] [blame^] | 71 | namespace 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 | } |