Issue 184081
Summary [clang-tidy] `readability-inconsistent-ifelse-braces` false positive with `[[likely]]` / `[[unlikely]]` attributes
Labels clang-tidy, false-positive
Assignees
Reporter tarun-t
     ### Description

  The `readability-inconsistent-ifelse-braces` check incorrectly reports "statement should have braces" when `[[likely]]` or `[[unlikely]]` is placed between the `if` condition and the opening brace. Both branches have braces — the check appears to not recognize the attribute as part of the attributed compound statement.

  ### Reproducer

  ```cpp
  // test.cpp
  void test_with_likely(int x) {
    if (x > 0) [[likely]] {
      x = 1;
    } else {
      x = 2;
    }
  }

  void test_without_likely(int x) {
    if (x > 0) {
      x = 1;
    } else {
      x = 2;
    }
  }

  $ clang-tidy-22 test.cpp --checks='-*,readability-inconsistent-ifelse-braces' -- -std=c++26
```
  Output
```
  test.cpp:2:13: warning: statement should have braces [readability-inconsistent-ifelse-braces]
      2 |   if (x > 0) [[likely]] {
        |             ^
        |              {
      3 |     x = 1;
      4 |   } else {
        |     }
```
  test_without_likely produces no warning. The only difference is the [[likely]] attribute.

  Expected behavior

  No warning — both branches are braced. The `[[likely]]` attribute on the compound statement should not affect brace consistency detection.

  Version

  Ubuntu clang version 22.1.1 (++20260228104553+108df0694cc1-1~exp1~20260228104610.34)

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to