llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

clang-tidy fix eliminates macro uses when the issue is in the macro (readability-else-after-return) #52828

Open joker-eph opened 2 years ago

joker-eph commented 2 years ago
#define CASE(x) \
  if (x) \
    return 1; \
  else \
    return 2; \

bool foo(bool x) {
  CASE(x);
}

After running $ clang-tidy /tmp/tidy.cpp --checks=readability-else-after-return -fix

/tmp/tidy.cpp:9:3: warning: do not use 'else' after 'return' [readability-else-after-return]
  CASE(x);
  ^~~~
/tmp/tidy.cpp:9:3: note: FIX-IT applied suggested code changes
/tmp/tidy.cpp:4:3: note: expanded from macro 'CASE'
  else \
  ^
clang-tidy applied 1 of 1 suggested fixes.

The use of the macro is weirdly deleted:

#define CASE(x) \
  if (x) \
    return 1; \
  else \
    return 2; \

bool foo(bool x) {
  (x);
}
llvmbot commented 2 years ago

@llvm/issue-subscribers-bug