[clang-tools-extra] r260952 - [clang-tidy] Fix an assert failure of ForStmt in `readability-braces-around-statements` check.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 16 02:31:33 PST 2016


Author: hokein
Date: Tue Feb 16 04:31:33 2016
New Revision: 260952

URL: http://llvm.org/viewvc/llvm-project?rev=260952&view=rev
Log:
[clang-tidy] Fix an assert failure of ForStmt in `readability-braces-around-statements` check.

Reviewers: alexfh

Subscribers: cfe-commits

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

Modified:
    clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-assert-failure.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=260952&r1=260951&r2=260952&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp Tue Feb 16 04:31:33 2016
@@ -215,6 +215,8 @@ bool BracesAroundStatementsCheck::checkS
     return false;
   }
 
+  if (!InitialLoc.isValid())
+    return false;
   const SourceManager &SM = *Result.SourceManager;
   const ASTContext *Context = Result.Context;
 
@@ -225,8 +227,6 @@ bool BracesAroundStatementsCheck::checkS
   if (FileRange.isInvalid())
     return false;
 
-  // InitialLoc points at the last token before opening brace to be inserted.
-  assert(InitialLoc.isValid());
   // Convert InitialLoc to file location, if it's on the same macro expansion
   // level as the start of the statement. We also need file locations for
   // Lexer::getLocForEndOfToken working properly.

Modified: 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=260952&r1=260951&r2=260952&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp Tue Feb 16 04:31:33 2016
@@ -1,7 +1,12 @@
-// RUN: %check_clang_tidy %s readability-braces-around-statements %t
+// RUN: clang-tidy -checks='-*,readability-braces-around-statements' %s --
+
+// Note: this test expects no assert failure happened in clang-tidy.
 
 int test_failure() {
   if (std::rand()) {
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: error: use of undeclared identifier 'std'
   }
 }
+
+void test_failure2() {
+  for (a b c;;
+}




More information about the cfe-commits mailing list