diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h --- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h +++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h @@ -27,6 +27,9 @@ void storeOptions(ClangTidyOptions::OptionMap &Options) override; void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; + llvm::Optional getCheckTraversalKind() const override { + return TK_IgnoreUnlessSpelledInSource; + } private: class Visitor; diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp --- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp @@ -71,10 +71,10 @@ } internal::BindableMatcher literalOrNegatedBool(bool Value) { - return expr(anyOf(cxxBoolLiteral(equals(Value)), - unaryOperator(hasUnaryOperand(ignoringParenImpCasts( - cxxBoolLiteral(equals(!Value)))), - hasOperatorName("!")))); + return expr( + anyOf(cxxBoolLiteral(equals(Value)), + unaryOperator(hasUnaryOperand(cxxBoolLiteral(equals(!Value))), + hasOperatorName("!")))); } internal::Matcher returnsBool(bool Value, StringRef Id = "ignored") { @@ -443,8 +443,7 @@ bool Value, StringRef BooleanId) { Finder->addMatcher( - ifStmt(unless(isInTemplateInstantiation()), - hasCondition(literalOrNegatedBool(Value).bind(BooleanId))) + ifStmt(hasCondition(literalOrNegatedBool(Value).bind(BooleanId))) .bind(IfStmtId), this); } @@ -453,8 +452,7 @@ bool Value, StringRef TernaryId) { Finder->addMatcher( - conditionalOperator(unless(isInTemplateInstantiation()), - hasTrueExpression(literalOrNegatedBool(Value)), + conditionalOperator(hasTrueExpression(literalOrNegatedBool(Value)), hasFalseExpression(literalOrNegatedBool(!Value))) .bind(TernaryId), this); @@ -463,14 +461,12 @@ void SimplifyBooleanExprCheck::matchIfReturnsBool(MatchFinder *Finder, bool Value, StringRef Id) { if (ChainedConditionalReturn) - Finder->addMatcher(ifStmt(unless(isInTemplateInstantiation()), - hasThen(returnsBool(Value, ThenLiteralId)), + Finder->addMatcher(ifStmt(hasThen(returnsBool(Value, ThenLiteralId)), hasElse(returnsBool(!Value))) .bind(Id), this); else - Finder->addMatcher(ifStmt(unless(isInTemplateInstantiation()), - unless(hasParent(ifStmt())), + Finder->addMatcher(ifStmt(unless(hasParent(ifStmt())), hasThen(returnsBool(Value, ThenLiteralId)), hasElse(returnsBool(!Value))) .bind(Id), @@ -495,16 +491,12 @@ auto Else = anyOf(SimpleElse, compoundStmt(statementCountIs(1), hasAnySubstatement(SimpleElse))); if (ChainedConditionalAssignment) - Finder->addMatcher(ifStmt(unless(isInTemplateInstantiation()), - hasThen(Then), hasElse(Else)) - .bind(Id), - this); + Finder->addMatcher(ifStmt(hasThen(Then), hasElse(Else)).bind(Id), this); else - Finder->addMatcher(ifStmt(unless(isInTemplateInstantiation()), - unless(hasParent(ifStmt())), hasThen(Then), - hasElse(Else)) - .bind(Id), - this); + Finder->addMatcher( + ifStmt(unless(hasParent(ifStmt())), hasThen(Then), hasElse(Else)) + .bind(Id), + this); } void SimplifyBooleanExprCheck::matchCompoundIfReturnsBool(MatchFinder *Finder, @@ -512,11 +504,9 @@ StringRef Id) { Finder->addMatcher( compoundStmt( - unless(isInTemplateInstantiation()), hasAnySubstatement( ifStmt(hasThen(returnsBool(Value)), unless(hasElse(stmt())))), - hasAnySubstatement(returnStmt(has(ignoringParenImpCasts( - literalOrNegatedBool(!Value)))) + hasAnySubstatement(returnStmt(has(literalOrNegatedBool(!Value))) .bind(CompoundReturnId))) .bind(Id), this);