Skip to content

Commit

Permalink
[ReachableCode] Skip over ExprWithCleanups in isConfigurationValue
Browse files Browse the repository at this point in the history
Summary: Fixes pr29152.

Reviewers: rsmith, pirama, krememek

Subscribers: cfe-commits

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

llvm-svn: 285657
  • Loading branch information
timshen91 committed Nov 1, 2016
1 parent 70c5f02 commit 43ee05e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clang/include/clang/AST/Stmt.h
Expand Up @@ -387,6 +387,9 @@ class alignas(void *) Stmt {
/// 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.
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Analysis/ReachableCode.cpp
Expand Up @@ -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();

Expand Down
15 changes: 15 additions & 0 deletions clang/test/SemaCXX/PR29152.cpp
@@ -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
}
}

0 comments on commit 43ee05e

Please sign in to comment.