diff options
author | Erik Pilkington <erik.pilkington@gmail.com> | 2019-01-08 00:21:05 +0000 |
---|---|---|
committer | Erik Pilkington <erik.pilkington@gmail.com> | 2019-01-08 00:21:05 +0000 |
commit | 2b01328de2b9738cf847a27b227eceac8ac5bcf6 (patch) | |
tree | 2a79cacc843ab53ec14f962495474d7fc48cda15 /test/SemaCXX | |
parent | 425b89a8d02393a39cfe223b84e3396841708794 (diff) |
Split -Wdelete-non-virtual-dtor into -Wdelete-abstract-non-virtual-dtor
-Wdelete-non-virtual-dtor previously controlled two diagnostics: 1)
calling a non-virtual dtor from an abstract class, and 2) calling a
non-virtual dtor from a polymorphic class. 1) is a lot more severe
than 2), since 1) is a guaranteed crash, but 2) is just "code smell".
Previously, projects compiled with -Wall -Wno-delete-non-virtual-dtor,
which is somewhat reasonable, silently crashed on 1).
rdar://40380564
Differential revision: https://reviews.llvm.org/D56405
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350585 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX')
-rw-r--r-- | test/SemaCXX/non-virtual-dtors.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/SemaCXX/non-virtual-dtors.cpp b/test/SemaCXX/non-virtual-dtors.cpp new file mode 100644 index 0000000000..230b899a7f --- /dev/null +++ b/test/SemaCXX/non-virtual-dtors.cpp @@ -0,0 +1,32 @@ +// RUN: %clang_cc1 %s -verify -DDIAG1 +// RUN: %clang_cc1 %s -verify -DDIAG1 -DDIAG2 -Wdelete-non-virtual-dtor +// RUN: %clang_cc1 %s -verify -DDIAG1 -Wmost -Wno-delete-non-virtual-dtor +// RUN: %clang_cc1 %s -verify -Wmost -Wno-delete-abstract-non-virtual-dtor + +#ifndef DIAG1 +#ifndef DIAG2 +// expected-no-diagnostics +#endif +#endif + +struct S1 { + ~S1() {} + virtual void abs() = 0; +}; + +void f1(S1 *s1) { delete s1; } +#ifdef DIAG1 +// expected-warning@-2 {{delete called on 'S1' that is abstract but has non-virtual destructor}} +#endif + +struct Base { + virtual void abs() = 0; +}; +struct S2 : Base { + ~S2() {} + void abs() {} +}; +void f2(S2 *s2) { delete s2; } +#ifdef DIAG2 +// expected-warning@-2 {{delete called on non-final 'S2' that has virtual functions but non-virtual destructor}} +#endif |