Skip to content

Commit

Permalink
[-Wunreachable-code] Tweak isTrivialDoWhile() to handle implicit casts.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204376 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tkremenek committed Mar 20, 2014
1 parent a8554f5 commit d3bf5b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Analysis/ReachableCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<DoStmt>(Term)) {
const Expr *Cond = DS->getCond();
const Expr *Cond = DS->getCond()->IgnoreParenCasts();
return Cond == S && isTrivialExpression(Cond);
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/SemaCXX/warn-unreachable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d3bf5b7

Please sign in to comment.