From: Ted Kremenek Date: Thu, 20 Mar 2014 18:47:53 +0000 (+0000) Subject: [-Wunreachable-code] Tweak isTrivialDoWhile() to handle implicit casts. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3bf5b7e901fa57569454195ad7d571859015c6c;p=clang [-Wunreachable-code] Tweak isTrivialDoWhile() to handle implicit casts. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204376 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/ReachableCode.cpp b/lib/Analysis/ReachableCode.cpp index 0a9e82bb0a..4220000cd3 100644 --- a/lib/Analysis/ReachableCode.cpp +++ b/lib/Analysis/ReachableCode.cpp @@ -51,7 +51,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt *S) { // condition. if (const Stmt *Term = B->getTerminator()) { if (const DoStmt *DS = dyn_cast(Term)) { - const Expr *Cond = DS->getCond(); + const Expr *Cond = DS->getCond()->IgnoreParenCasts(); return Cond == S && isTrivialExpression(Cond); } } diff --git a/test/SemaCXX/warn-unreachable.cpp b/test/SemaCXX/warn-unreachable.cpp index 7f74732a63..eab8d8e6b9 100644 --- a/test/SemaCXX/warn-unreachable.cpp +++ b/test/SemaCXX/warn-unreachable.cpp @@ -218,6 +218,14 @@ int test_treat_non_const_bool_local_as_non_config_value() { return 0; } +void test_do_while(int x) { + // Handle trivial expressions with + // implicit casts to bool. + do { + break; + } while (0); // no-warning +} + class Frobozz { public: Frobozz(int x);