diff --git a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp @@ -186,6 +186,10 @@ bool BracesAroundStatementsCheck::checkStmt( const MatchFinder::MatchResult &Result, const Stmt *S, SourceLocation InitialLoc, SourceLocation EndLocHint) { + + while (const auto *AS = dyn_cast(S)) + S = AS->getSubStmt(); + // 1) If there's a corresponding "else" or "while", the check inserts "} " // right before that token. // 2) If there's a multi-line block comment starting on the same line after diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-attributes.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-attributes.cpp new file mode 100644 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/readability-braces-around-statements-attributes.cpp @@ -0,0 +1,24 @@ +// RUN: %check_clang_tidy -std=c++20-or-later %s readability-braces-around-statements %t + +void test(bool b) { + if (b) { + return; + } + if (b) [[likely]] { + // CHECK-FIXES-NOT: if (b) { {{[[][[]}}likely{{[]][]]}} { + return; + } + if (b) [[unlikely]] { + // CHECK-FIXES-NOT: if (b) { {{[[][[]}}unlikely{{[]][]]}} { + return; + } + + if (b) [[likely]] + // CHECK-FIXES: if (b) {{[[][[]}}likely{{[]][]]}} { + return; + // CHECK-FIXES: } + if (b) [[unlikely]] + // CHECK-FIXES: if (b) {{[[][[]}}unlikely{{[]][]]}} { + return; + // CHECK-FIXES: } +}