================
@@ -0,0 +1,35 @@
+// RUN: %check_clang_tidy -std=c++20-or-later %s
readability-inconsistent-ifelse-braces %t
+
+void do_something(const char *) {}
+
+// Positive tests.
+void f(bool b) {
+ if (b) [[likely]] do_something("if-same-line");
+ else {
+ }
+ // CHECK-MESSAGES: :[[@LINE-3]]:9: warning: <message>
[readability-inconsistent-ifelse-braces]
+ // CHECK-FIXES: if (b) { {{[[][[]}}likely{{[]][]]}}
do_something("if-same-line");
+ // CHECK-FIXES: } else {
----------------
capitan-davide wrote:
I was adding some tests with likely/unlikely attributes but this fix-it seems
wrong to me (which is the same applied by
`readability-braces-around-statements`). From:
```c++
if (b) [[likely]] do_something("if-same-line");
else {
}
```
To:
```c++
if (b) { [[likely]] do_something("if-same-line");
} else {
}
```
Also [cppreference](https://en.cppreference.com/w/cpp/language/if.html) is not
clear on where these attributes should be placed.
What do you think? Are these semanically equivalent?
```c++
[[likely]] if (b) do_something(); // (A)
if (b) [[likely]] do_something(); // (B)
if (b) { [[likely]] do_something(); } // (C)
```
https://github.com/llvm/llvm-project/pull/162361
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits