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

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 11 01:57:56 PST 2016


Author: hokein
Date: Thu Feb 11 03:57:55 2016
New Revision: 260505

URL: http://llvm.org/viewvc/llvm-project?rev=260505&view=rev
Log:
[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

Added:
    clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp
Modified:
    clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp?rev=260505&r1=260504&r2=260505&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp Thu Feb 11 03:57:55 2016
@@ -180,7 +180,10 @@ BracesAroundStatementsCheck::findRParenL
   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())

Added: clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp?rev=260505&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp Thu Feb 11 03:57:55 2016
@@ -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'
+  }
+}




More information about the cfe-commits mailing list