Index: clang-tidy/readability/BracesAroundStatementsCheck.cpp =================================================================== --- clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -215,6 +215,8 @@ return false; } + if (!InitialLoc.isValid()) + return false; const SourceManager &SM = *Result.SourceManager; const ASTContext *Context = Result.Context; @@ -225,8 +227,6 @@ 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. Index: test/clang-tidy/readability-braces-around-statements-assert-failure.cpp =================================================================== --- test/clang-tidy/readability-braces-around-statements-assert-failure.cpp +++ test/clang-tidy/readability-braces-around-statements-assert-failure.cpp @@ -5,3 +5,22 @@ // CHECK-MESSAGES: :[[@LINE-1]]:7: error: use of undeclared identifier 'std' } } + +#include + +int test_failure2() { + std::vector e; + for (typename std::vector::const_reverse_iterator iter = e.begin(), + end2 = e.end(); + iter != end2; ++iter) { + // CHECK-MESSAGES: :[[@LINE-3]]:29: error: use of undeclared identifier 'T' + // CHECK-MESSAGES: :[[@LINE-4]]:33: error: no type named 'const_reverse_iterator' in the global namespace + // CHECK-MESSAGES: :[[@LINE-4]]:61: error: expected ';' in 'for' statement specifier + // CHECK-MESSAGES: :[[@LINE-5]]:61: error: expected expression + // CHECK-MESSAGES: :[[@LINE-5]]:16: error: use of undeclared identifier 'end2' + // CHECK-MESSAGES: :[[@LINE-6]]:20: error: expected ')' + // CHECK-MESSAGES: :[[@LINE-7]]:24: error: use of undeclared identifier 'iter' + // CHECK-MESSAGES: :[[@LINE-8]]:28: error: expected ';' after expression + // CHECK-MESSAGES: :[[@LINE-9]]:28: error: expected expression + } +}