[clang-tools-extra] [clang-tidy] Correctly handle attributes in readability-inconsistent-ifelse-braces (PR #184095)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 2 17:53:26 PST 2026
================
@@ -14,6 +14,20 @@ void f(bool b) {
return;
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: statement should have braces [readability-inconsistent-ifelse-braces]
// CHECK-FIXES: } else { {{[[][[]}}unlikely{{[]][]]}}
+
+ if (b) [[likely]] {
+ } else [[unlikely]]
+ return;
+ // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: statement should have braces [readability-inconsistent-ifelse-braces]
+ // CHECK-FIXES: } else { {{[[][[]}}unlikely{{[]][]]}}
+
+ if (b) [[likely]]
+ return;
+ else [[unlikely]] {
+ }
+ // CHECK-MESSAGES: :[[@LINE-4]]:9: warning: statement should have braces [readability-inconsistent-ifelse-braces]
+ // CHECK-FIXES: if (b) { {{[[][[]}}likely{{[]][]]}}
----------------
zwuis wrote:
It's up to you, but it would be better to not hard-code where to add braces.
```diff
// expected fix-it, explicitly ignore return value
-if (b) [[maybe_unused]] auto _ = foo();
+if (b) { [[maybe_unused]] auto _ = foo(); }
else {
}
```
https://github.com/llvm/llvm-project/pull/184095
More information about the cfe-commits
mailing list