summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis/NewDelete-checker-test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test/Analysis/NewDelete-checker-test.cpp')
-rw-r--r--clang/test/Analysis/NewDelete-checker-test.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/test/Analysis/NewDelete-checker-test.cpp b/clang/test/Analysis/NewDelete-checker-test.cpp
index 442b8fbef09..cc9725128bc 100644
--- a/clang/test/Analysis/NewDelete-checker-test.cpp
+++ b/clang/test/Analysis/NewDelete-checker-test.cpp
@@ -333,3 +333,28 @@ namespace reference_count {
}
}
+// Test double delete
+class DerefClass{
+public:
+ int *x;
+ DerefClass() {}
+ ~DerefClass() {*x = 1;} //expected-warning {{Use of memory after it is freed}}
+};
+
+void testDoubleDeleteClassInstance() {
+ DerefClass *foo = new DerefClass();
+ delete foo;
+ delete foo; // FIXME: We should ideally report warning here instead of inside the destructor.
+}
+
+class EmptyClass{
+public:
+ EmptyClass() {}
+ ~EmptyClass() {}
+};
+
+void testDoubleDeleteEmptyClass() {
+ EmptyClass *foo = new EmptyClass();
+ delete foo;
+ delete foo; //expected-warning {{Attempt to free released memory}}
+}
OpenPOWER on IntegriCloud