aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Analysis/CheckDeadStores.cpp4
-rw-r--r--test/Analysis/dead-stores.cpp20
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/Analysis/CheckDeadStores.cpp b/lib/Analysis/CheckDeadStores.cpp
index ec13328447..db9016fa1e 100644
--- a/lib/Analysis/CheckDeadStores.cpp
+++ b/lib/Analysis/CheckDeadStores.cpp
@@ -186,6 +186,10 @@ public:
if (V->hasLocalStorage())
if (Expr* E = V->getInit()) {
+ // Don't warn on C++ objects (yet) until we can show that their
+ // constructors/destructors don't have side effects.
+ if (isa<CXXConstructExpr>(E))
+ return;
// A dead initialization is a variable that is dead after it
// is initialized. We don't flag warnings for those variables
// marked 'unused'.
diff --git a/test/Analysis/dead-stores.cpp b/test/Analysis/dead-stores.cpp
index 1bab9f4bad..363cfdd98c 100644
--- a/test/Analysis/dead-stores.cpp
+++ b/test/Analysis/dead-stores.cpp
@@ -4,6 +4,10 @@
// RUN: clang -cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -warn-dead-stores -verify %s
// RUN: clang -cc1 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -warn-dead-stores -verify %s
+//===----------------------------------------------------------------------===//
+// Basic dead store checking (but in C++ mode).
+//===----------------------------------------------------------------------===//
+
int j;
void f1() {
int x = 4;
@@ -17,3 +21,19 @@ void f1() {
break;
}
}
+
+//===----------------------------------------------------------------------===//
+// Dead store checking involving constructors.
+//===----------------------------------------------------------------------===//
+
+class Test1 {
+ int &x;
+public:
+ Test1(int &y) : x(y) {}
+ ~Test1() { ++x; }
+};
+
+int test_ctor_1(int x) {
+ { Test1 a(x); } // no-warning
+ return x;
+}