[PATCH] D26125: [clang-tidy] Fixed else-after-return warning in cascade if statement
Paweł Żukowski via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 30 08:31:47 PDT 2016
idlecode marked an inline comment as done.
idlecode added inline comments.
================
Comment at: clang-tidy/readability/ElseAfterReturnCheck.cpp:28
stmt(forEach(
- ifStmt(hasThen(stmt(
+ ifStmt(unless(hasParent(ifStmt())),
+ hasThen(stmt(
----------------
djasper wrote:
> I think this now effectively does:
>
> stmt(forEach(ifStmt(unless(hasParent(ifSttmt())), ...)
>
> I think that's equivalent to:
>
> stmt(unless(ifStmt()), forEach(ifStmt(...)))
Apparently you are right - does that mean that this matcher actually matches node above ifStmt (and just binds ifStmt)?
If so maybe such expression would suffice? (it passes tests)
```
Finder->addMatcher( // note lack of stmt(forEach(
ifStmt(unless(hasParent(ifStmt())),
hasThen(stmt(
anyOf(ControlFlowInterruptorMatcher,
compoundStmt(has(ControlFlowInterruptorMatcher))))),
hasElse(stmt().bind("else")))
.bind("if"),
this);
```
But I'm not sure if this would be any better than your version.
https://reviews.llvm.org/D26125
More information about the cfe-commits
mailing list