[PATCH] D91485: [clang-tidy] ElseAfterReturn check wont suggest fixes if preprocessor branches are involved

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 17 13:32:16 PST 2020


njames93 marked 8 inline comments as done.
njames93 added inline comments.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/readability-else-after-return.cpp:313
+#endif
+}
----------------
aaron.ballman wrote:
> We should probably add some tests for more pathological cases, like:
> ```
> #if 1
> if (true) {
>   return;
> #else
> {
> #endif
> } else {
>   return;
> }
> ```
I'm don't even think its worth adding tests for that kind of code. Its impossible to reason about at the AST level(we dont get any AST for discarded pp conditional branches). So for these or cases like :
```lang=c++
if (true) {
#if 1
  return;
} else {
#endif
  return;
}
```
Its just simpler to leave the behaviour as is and hope that a user sees the change and addresses (or suppresses) it manually.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91485/new/

https://reviews.llvm.org/D91485



More information about the cfe-commits mailing list