diff --git a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h --- a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.h @@ -26,6 +26,9 @@ : ClangTidyCheck(Name, Context) {} void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; + llvm::Optional getCheckTraversalKind() const override { + return TK_IgnoreUnlessSpelledInSource; + } }; } // namespace bugprone diff --git a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp --- a/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp @@ -48,23 +48,23 @@ .bind(CondVarStr); Finder->addMatcher( ifStmt( - hasCondition(ignoringParenImpCasts(anyOf( + hasCondition(anyOf( declRefExpr(hasDeclaration(ImmutableVar)).bind(OuterIfVar1Str), - binaryOperator(hasOperatorName("&&"), - hasEitherOperand(ignoringParenImpCasts( - declRefExpr(hasDeclaration(ImmutableVar)) - .bind(OuterIfVar2Str))))))), + binaryOperator( + hasOperatorName("&&"), + hasEitherOperand(declRefExpr(hasDeclaration(ImmutableVar)) + .bind(OuterIfVar2Str))))), hasThen(hasDescendant( - ifStmt(hasCondition(ignoringParenImpCasts( - anyOf(declRefExpr(hasDeclaration(varDecl( - equalsBoundNode(CondVarStr)))) - .bind(InnerIfVar1Str), - binaryOperator( - hasAnyOperatorName("&&", "||"), - hasEitherOperand(ignoringParenImpCasts( - declRefExpr(hasDeclaration(varDecl( + ifStmt(hasCondition(anyOf( + declRefExpr(hasDeclaration( + varDecl(equalsBoundNode(CondVarStr)))) + .bind(InnerIfVar1Str), + binaryOperator( + hasAnyOperatorName("&&", "||"), + hasEitherOperand( + declRefExpr(hasDeclaration(varDecl( equalsBoundNode(CondVarStr)))) - .bind(InnerIfVar2Str)))))))) + .bind(InnerIfVar2Str)))))) .bind(InnerIfStr))), forFunction(functionDecl().bind(FuncStr))) .bind(OuterIfStr),