destructor.cpp revision 5efd91a3b58e59006f8a3e8c9256ec00c38dba95
1// RUN: %clang_cc1 -fsyntax-only -verify %s
2class A {
3public:
4  ~A();
5};
6
7class B {
8public:
9  ~B() { }
10};
11
12class C {
13public:
14  (~C)() { }
15};
16
17struct D {
18  static void ~D(int, ...) const { } //                          \
19    // expected-error{{type qualifier is not allowed on this function}} \
20    // expected-error{{destructor cannot be declared 'static'}}  \
21    // expected-error{{destructor cannot have any parameters}}   \
22    // expected-error{{destructor cannot be variadic}} \
23    // expected-error{{destructor cannot have a return type}} \
24    // expected-error{{'const' qualifier is not allowed on a destructor}}
25};
26
27struct D2 {
28  void ~D2() { } //                          \
29  // expected-error{{destructor cannot have a return type}}
30};
31
32
33struct E;
34
35typedef E E_typedef;
36struct E {
37  ~E_typedef(); // expected-error{{destructor cannot be declared using a typedef 'E_typedef' (aka 'E') of the class name}}
38};
39
40struct F {
41  (~F)(); // expected-note {{previous declaration is here}}
42  ~F(); // expected-error {{destructor cannot be redeclared}}
43};
44
45~; // expected-error {{expected a class name after '~' to name a destructor}}
46~undef(); // expected-error {{expected the class name after '~' to name a destructor}}
47~operator+(int, int);  // expected-error {{expected a class name after '~' to name a destructor}}
48~F(){} // expected-error {{destructor must be a non-static member function}}
49
50struct G {
51  ~G();
52};
53
54G::~G() { }
55
56// <rdar://problem/6841210>
57struct H {
58  ~H(void) { }
59};
60
61struct X {};
62
63struct Y {
64  ~X(); // expected-error {{expected the class name after '~' to name the enclosing class}}
65};
66
67namespace PR6421 {
68  class T; // expected-note{{forward declaration}}
69
70  class QGenericArgument
71  {
72    template<typename U>
73    void foo(T t) // expected-error{{variable has incomplete type}}
74    { }
75
76    void disconnect()
77    {
78      T* t;
79      bob<QGenericArgument>(t); // expected-error{{undeclared identifier 'bob'}}
80    }
81  };
82}
83
84namespace PR6709 {
85  template<class T> class X { T v; ~X() { ++*v; } };
86  void a(X<int> x) {}
87}
88
89struct X0 { virtual ~X0() throw(); };
90struct X1 : public X0 { };
91
92// Make sure we instantiate operator deletes when building a virtual
93// destructor.
94namespace test6 {
95  template <class T> class A {
96  public:
97    void *operator new(unsigned long);
98    void operator delete(void *p) {
99      T::deleteIt(p); // expected-error {{type 'int' cannot be used prior to '::'}}
100    }
101
102    virtual ~A() {} // expected-note {{in instantiation of member function 'test6::A<int>::operator delete' requested here}}
103  };
104
105  class B : A<int> { B(); };
106  B::B() {}
107}
108