[PATCH] D17069: [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 02:02:17 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL260505: [clang-tidy] Fix an assert failure in 'readability-braces-around-statements'… (authored by hokein).

Changed prior to commit:
  http://reviews.llvm.org/D17069?vs=47609&id=47610#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17069

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

Index: clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/BracesAroundStatementsCheck.cpp
@@ -180,7 +180,10 @@
   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())
Index: clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp
@@ -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'
+  }
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17069.47610.patch
Type: text/x-patch
Size: 1292 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160211/dbd7f74e/attachment.bin>


More information about the cfe-commits mailing list