PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/test/SemaCXX/destructor.cpp

http://github.com/klimek/clang-indent
C++ | 192 lines | 140 code | 38 blank | 14 comment | 0 complexity | 25bd1656a7c4fc6b1bdac6c11293ebc6 MD5 | raw file
Possible License(s): JSON
  1. // RUN: %clang_cc1 -fsyntax-only -Wnon-virtual-dtor -verify %s
  2. class A {
  3. public:
  4. ~A();
  5. };
  6. class B {
  7. public:
  8. ~B() { }
  9. };
  10. class C {
  11. public:
  12. (~C)() { }
  13. };
  14. struct D {
  15. static void ~D(int, ...) const { } // \
  16. // expected-error{{type qualifier is not allowed on this function}} \
  17. // expected-error{{destructor cannot be declared 'static'}} \
  18. // expected-error{{destructor cannot have any parameters}} \
  19. // expected-error{{destructor cannot be variadic}} \
  20. // expected-error{{destructor cannot have a return type}} \
  21. // expected-error{{'const' qualifier is not allowed on a destructor}}
  22. };
  23. struct D2 {
  24. void ~D2() { } // \
  25. // expected-error{{destructor cannot have a return type}}
  26. };
  27. struct E;
  28. typedef E E_typedef;
  29. struct E {
  30. ~E_typedef(); // expected-error{{destructor cannot be declared using a typedef 'E_typedef' (aka 'E') of the class name}}
  31. };
  32. struct F {
  33. (~F)(); // expected-note {{previous declaration is here}}
  34. ~F(); // expected-error {{destructor cannot be redeclared}}
  35. };
  36. ~; // expected-error {{expected a class name after '~' to name a destructor}}
  37. ~undef(); // expected-error {{expected the class name after '~' to name a destructor}}
  38. ~operator+(int, int); // expected-error {{expected a class name after '~' to name a destructor}}
  39. ~F(){} // expected-error {{destructor must be a non-static member function}}
  40. struct G {
  41. ~G();
  42. };
  43. G::~G() { }
  44. // <rdar://problem/6841210>
  45. struct H {
  46. ~H(void) { }
  47. };
  48. struct X {};
  49. struct Y {
  50. ~X(); // expected-error {{expected the class name after '~' to name the enclosing class}}
  51. };
  52. namespace PR6421 {
  53. class T; // expected-note{{forward declaration}}
  54. class QGenericArgument // expected-note{{declared here}}
  55. {
  56. template<typename U>
  57. void foo(T t) // expected-error{{variable has incomplete type}}
  58. { }
  59. void disconnect()
  60. {
  61. T* t;
  62. bob<QGenericArgument>(t); // expected-error{{undeclared identifier 'bob'}} \
  63. // expected-error{{does not refer to a value}}
  64. }
  65. };
  66. }
  67. namespace PR6709 {
  68. template<class T> class X { T v; ~X() { ++*v; } };
  69. void a(X<int> x) {}
  70. }
  71. struct X0 { virtual ~X0() throw(); };
  72. struct X1 : public X0 { };
  73. // Make sure we instantiate operator deletes when building a virtual
  74. // destructor.
  75. namespace test6 {
  76. template <class T> class A {
  77. public:
  78. void *operator new(__SIZE_TYPE__);
  79. void operator delete(void *p) {
  80. T::deleteIt(p); // expected-error {{type 'int' cannot be used prior to '::'}}
  81. }
  82. virtual ~A() {}
  83. };
  84. class B : A<int> { B(); }; // expected-note {{in instantiation of member function 'test6::A<int>::operator delete' requested here}}
  85. B::B() {}
  86. }
  87. // Make sure classes are marked invalid when they have invalid
  88. // members. This avoids a crash-on-invalid.
  89. namespace test7 {
  90. struct A {
  91. ~A() const; // expected-error {{'const' qualifier is not allowed on a destructor}}
  92. };
  93. struct B : A {};
  94. void test() {
  95. B *b;
  96. b->~B();
  97. }
  98. }
  99. namespace nonvirtualdtor {
  100. struct S1 { // expected-warning {{has virtual functions but non-virtual destructor}}
  101. virtual void m();
  102. };
  103. struct S2 {
  104. ~S2(); // expected-warning {{has virtual functions but non-virtual destructor}}
  105. virtual void m();
  106. };
  107. struct S3 : public S1 { // expected-warning {{has virtual functions but non-virtual destructor}}
  108. virtual void m();
  109. };
  110. struct S4 : public S2 { // expected-warning {{has virtual functions but non-virtual destructor}}
  111. virtual void m();
  112. };
  113. struct B {
  114. virtual ~B();
  115. virtual void m();
  116. };
  117. struct S5 : public B {
  118. virtual void m();
  119. };
  120. struct S6 {
  121. virtual void m();
  122. private:
  123. ~S6();
  124. };
  125. struct S7 {
  126. virtual void m();
  127. protected:
  128. ~S7();
  129. };
  130. template<class T> class TS : public B {
  131. virtual void m();
  132. };
  133. TS<int> baz;
  134. template<class T> class TS2 { // expected-warning {{'nonvirtualdtor::TS2<int>' has virtual functions but non-virtual destructor}}
  135. virtual void m();
  136. };
  137. TS2<int> foo; // expected-note {{instantiation}}
  138. }
  139. namespace PR9238 {
  140. class B { public: ~B(); };
  141. class C : virtual B { public: ~C() { } };
  142. }
  143. namespace PR7900 {
  144. struct A { // expected-note 2{{type 'PR7900::A' is declared here}}
  145. };
  146. struct B : public A {
  147. };
  148. void foo() {
  149. B b;
  150. b.~B();
  151. b.~A(); // expected-error{{destructor type 'PR7900::A' in object destruction expression does not match the type 'PR7900::B' of the object being destroyed}}
  152. (&b)->~A(); // expected-error{{destructor type 'PR7900::A' in object destruction expression does not match the type 'PR7900::B' of the object being destroyed}}
  153. }
  154. }