[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / delete-non-virtual-dtor.cpp
blobb64eca3527f3eed0e3f1f869816c1aeafeaee6e4
1 // RUN: %clang_cc1 %s -verify -DDIAG1
2 // RUN: %clang_cc1 %s -verify -DDIAG1 -DDIAG2 -Wdelete-non-virtual-dtor
3 // RUN: %clang_cc1 %s -verify -DDIAG1 -Wmost -Wno-delete-non-abstract-non-virtual-dtor
4 // RUN: %clang_cc1 %s -verify -DDIAG2 -Wmost -Wno-delete-abstract-non-virtual-dtor
5 // RUN: %clang_cc1 %s -verify -Wmost -Wno-delete-non-virtual-dtor
7 #ifndef DIAG1
8 #ifndef DIAG2
9 // expected-no-diagnostics
10 #endif
11 #endif
13 struct S1 {
14 ~S1() {}
15 virtual void abs() = 0;
18 void f1(S1 *s1) { delete s1; }
19 #ifdef DIAG1
20 // expected-warning@-2 {{delete called on 'S1' that is abstract but has non-virtual destructor}}
21 #endif
23 struct S2 {
24 ~S2() {}
25 virtual void real() {}
27 void f2(S2 *s2) { delete s2; }
28 #ifdef DIAG2
29 // expected-warning@-2 {{delete called on non-final 'S2' that has virtual functions but non-virtual destructor}}
30 #endif