Skip to content

Commit a5feefa

Browse files
committed
[clang-tidy] Simplify redundant branch condition check
Differential Revision: https://reviews.llvm.org/D97151
1 parent df42f99 commit a5feefa

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@ void RedundantBranchConditionCheck::registerMatchers(MatchFinder *Finder) {
4848
.bind(CondVarStr);
4949
Finder->addMatcher(
5050
ifStmt(
51-
hasCondition(ignoringParenImpCasts(anyOf(
51+
hasCondition(anyOf(
5252
declRefExpr(hasDeclaration(ImmutableVar)).bind(OuterIfVar1Str),
53-
binaryOperator(hasOperatorName("&&"),
54-
hasEitherOperand(ignoringParenImpCasts(
55-
declRefExpr(hasDeclaration(ImmutableVar))
56-
.bind(OuterIfVar2Str))))))),
53+
binaryOperator(
54+
hasOperatorName("&&"),
55+
hasEitherOperand(declRefExpr(hasDeclaration(ImmutableVar))
56+
.bind(OuterIfVar2Str))))),
5757
hasThen(hasDescendant(
58-
ifStmt(hasCondition(ignoringParenImpCasts(
59-
anyOf(declRefExpr(hasDeclaration(varDecl(
60-
equalsBoundNode(CondVarStr))))
61-
.bind(InnerIfVar1Str),
62-
binaryOperator(
63-
hasAnyOperatorName("&&", "||"),
64-
hasEitherOperand(ignoringParenImpCasts(
65-
declRefExpr(hasDeclaration(varDecl(
58+
ifStmt(hasCondition(anyOf(
59+
declRefExpr(hasDeclaration(
60+
varDecl(equalsBoundNode(CondVarStr))))
61+
.bind(InnerIfVar1Str),
62+
binaryOperator(
63+
hasAnyOperatorName("&&", "||"),
64+
hasEitherOperand(
65+
declRefExpr(hasDeclaration(varDecl(
6666
equalsBoundNode(CondVarStr))))
67-
.bind(InnerIfVar2Str))))))))
67+
.bind(InnerIfVar2Str))))))
6868
.bind(InnerIfStr))),
6969
forFunction(functionDecl().bind(FuncStr)))
7070
.bind(OuterIfStr),

clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class RedundantBranchConditionCheck : public ClangTidyCheck {
2626
: ClangTidyCheck(Name, Context) {}
2727
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2828
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
29+
llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
30+
return TK_IgnoreUnlessSpelledInSource;
31+
}
2932
};
3033

3134
} // namespace bugprone

0 commit comments

Comments
 (0)