]> granicus.if.org Git - clang/commitdiff
[ReachableCode] Skip over ExprWithCleanups in isConfigurationValue
authorTim Shen <timshen91@gmail.com>
Tue, 1 Nov 2016 00:19:04 +0000 (00:19 +0000)
committerTim Shen <timshen91@gmail.com>
Tue, 1 Nov 2016 00:19:04 +0000 (00:19 +0000)
Summary: Fixes pr29152.

Reviewers: rsmith, pirama, krememek

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D24010

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285657 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Stmt.h
lib/Analysis/ReachableCode.cpp
test/SemaCXX/PR29152.cpp [new file with mode: 0644]

index 9381a44985f448d860c567ce20e5eaa183e8a87a..e28675d6a828fafd178871cabf23b1420f5a7a14 100644 (file)
@@ -387,6 +387,9 @@ public:
   /// Skip past any implicit AST nodes which might surround this
   /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
   Stmt *IgnoreImplicit();
+  const Stmt *IgnoreImplicit() const {
+    return const_cast<Stmt *>(this)->IgnoreImplicit();
+  }
 
   /// \brief Skip no-op (attributed, compound) container stmts and skip captured
   /// stmt at the top, if \a IgnoreCaptured is true.
index 8165b09f408005454321e5e1c588e38e8004bde1..69d000c03bac130993c0faea7f6a3f3e02ed99a8 100644 (file)
@@ -164,6 +164,8 @@ static bool isConfigurationValue(const Stmt *S,
   if (!S)
     return false;
 
+  S = S->IgnoreImplicit();
+
   if (const Expr *Ex = dyn_cast<Expr>(S))
     S = Ex->IgnoreCasts();
 
diff --git a/test/SemaCXX/PR29152.cpp b/test/SemaCXX/PR29152.cpp
new file mode 100644 (file)
index 0000000..63c9c9b
--- /dev/null
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunreachable-code -verify %s
+
+static const bool False = false;
+
+struct A {
+  ~A();
+  operator bool();
+};
+void Bar();
+
+void Foo() {
+  if (False && A()) {
+    Bar(); // expected-no-diagnostics
+  }
+}