This revision was automatically updated to reflect the committed changes. Closed by commit rG302cc8421ee4: [clang-tidy] Simplify boolean expr check (authored by stephenkelly).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97153/new/ https://reviews.llvm.org/D97153 Files: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h =================================================================== --- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h +++ 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<TraversalKind> getCheckTraversalKind() const override { + return TK_IgnoreUnlessSpelledInSource; + } private: class Visitor; Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp +++ clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp @@ -71,10 +71,10 @@ } internal::BindableMatcher<Stmt> 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<Stmt> 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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits