[clang-tidy] Fix an assert failure in 'readability-braces-around-statements' check.

Summary:
The check will trigger a assert failure("CondEndLoc.isValid") when
checking the IfStmt whose condition expression is not parsed.

In this case, we should ignore that.

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D17069

llvm-svn: 260505
This commit is contained in:
Haojian Wu 2016-02-11 09:57:55 +00:00
parent 2260a3a046
commit 60c9316d62
2 changed files with 11 additions and 1 deletions

View File

@ -180,7 +180,10 @@ BracesAroundStatementsCheck::findRParenLoc(const IfOrWhileStmt *S,
if (const DeclStmt *CondVar = S->getConditionVariableDeclStmt())
CondEndLoc = CondVar->getLocEnd();
assert(CondEndLoc.isValid());
if (!CondEndLoc.isValid()) {
return SourceLocation();
}
SourceLocation PastCondEndLoc =
Lexer::getLocForEndOfToken(CondEndLoc, 0, SM, Context->getLangOpts());
if (PastCondEndLoc.isInvalid())

View File

@ -0,0 +1,7 @@
// RUN: %check_clang_tidy %s readability-braces-around-statements %t
int test_failure() {
if (std::rand()) {
// CHECK-MESSAGES: :[[@LINE-1]]:7: error: use of undeclared identifier 'std'
}
}