diff options
| -rw-r--r-- | clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp | 4 | ||||
| -rw-r--r-- | clang-tools-extra/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp index 629388100c1..d65f60ba5bd 100644 --- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -215,6 +215,8 @@ bool BracesAroundStatementsCheck::checkStmt( return false; } + if (!InitialLoc.isValid()) + return false; const SourceManager &SM = *Result.SourceManager; const ASTContext *Context = Result.Context; @@ -225,8 +227,6 @@ bool BracesAroundStatementsCheck::checkStmt( 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. diff --git a/clang-tools-extra/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp b/clang-tools-extra/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp index fe9bcf4e9d1..146268709e2 100644 --- a/clang-tools-extra/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp +++ b/clang-tools-extra/test/clang-tidy/readability-braces-around-statements-assert-failure.cpp @@ -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;; +} |

