Index: clang-tidy/readability/BracesAroundStatementsCheck.cpp =================================================================== --- clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -60,8 +60,18 @@ assert(Loc.isValid()); bool SkipEndWhitespaceAndComments = true; tok::TokenKind TokKind = getTokenKind(Loc, SM, Context); + // If we are at "}", but the following token is ";", then we could be + // reading a statement like "x = A{};" and "}" does not mean we reached + // the end of a statement. Hence we look ahead. + SourceLocation LocOneAhead = forwardSkipWhitespaceAndComments(Loc.getLocWithOffset(1), SM, Context); + tok::TokenKind OneAheadTokKind; + if (LocOneAhead.isValid()) { + OneAheadTokKind = getTokenKind(LocOneAhead, SM, Context); + } else { + OneAheadTokKind = tok::NUM_TOKENS; + } if (TokKind == tok::NUM_TOKENS || TokKind == tok::semi || - TokKind == tok::r_brace) { + (TokKind == tok::r_brace && OneAheadTokKind != tok::semi)) { // If we are at ";" or "}", we found the last token. We could use as well // `if (isa(S))`, but it wouldn't work for nested statements. SkipEndWhitespaceAndComments = false; Index: test/clang-tidy/readability-braces-around-statements.cpp =================================================================== --- test/clang-tidy/readability-braces-around-statements.cpp +++ test/clang-tidy/readability-braces-around-statements.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s readability-braces-around-statements %t +// RUN: %check_clang_tidy %s readability-braces-around-statements %t -- -- -std=c++11 void do_something(const char *) {} @@ -21,6 +21,19 @@ // CHECK-FIXES: if (cond("if0.1")) { // CHECK-FIXES: } + int s; + if (cond("c++11 initialization")) + s = int{}; + // CHECK-MESSAGES: :[[@LINE-2]]:36: warning: statement should be inside braces + // CHECK-FIXES: if (cond("c++11 initialization")) { + // CHECK-FIXES: } + + for (;;) + s = int{}; + // CHECK-MESSAGES: :[[@LINE-2]]:11: warning: statement should be inside braces + // CHECK-FIXES: for (;;) + // CHECK-FIXES: } + if (cond("if1") /*comment*/) // some comment do_something("if1");