summaryrefslogtreecommitdiff
path: root/test/SemaCXX
diff options
context:
space:
mode:
authorErik Pilkington <erik.pilkington@gmail.com>2019-01-10 18:03:07 +0000
committerErik Pilkington <erik.pilkington@gmail.com>2019-01-10 18:03:07 +0000
commit1581cdda759fb5b516ff2de1eb2aabf38fe7a7a4 (patch)
treeea6622ca47214473b95a45bfb3237baf4a47a008 /test/SemaCXX
parent97d939ee57f80d052d5b55dba51046f6aa459582 (diff)
downloadclang-1581cdda759fb5b516ff2de1eb2aabf38fe7a7a4.tar.gz
Split -Wdelete-non-virtual-dtor into two groups
This group controls two diagnostics: deleting an abstract class with a non-virtual dtor, which is a guaranteed crash, and deleting a non-abstract polymorphic class with a non-virtual dtor, which is just suspicious. rdar://40380564 Differential revision: https://reviews.llvm.org/D56405 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350856 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX')
-rw-r--r--test/SemaCXX/delete-non-virtual-dtor.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/SemaCXX/delete-non-virtual-dtor.cpp b/test/SemaCXX/delete-non-virtual-dtor.cpp
new file mode 100644
index 0000000000..b64eca3527
--- /dev/null
+++ b/test/SemaCXX/delete-non-virtual-dtor.cpp
@@ -0,0 +1,30 @@
+// 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-abstract-non-virtual-dtor
+// RUN: %clang_cc1 %s -verify -DDIAG2 -Wmost -Wno-delete-abstract-non-virtual-dtor
+// RUN: %clang_cc1 %s -verify -Wmost -Wno-delete-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 S2 {
+ ~S2() {}
+ virtual void real() {}
+};
+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