steveire updated this revision to Diff 313370. steveire added a comment. Update
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91303/new/ https://reviews.llvm.org/D91303 Files: clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp +++ clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp @@ -695,7 +695,4 @@ struct StructWithLazyNoexcept { void func() noexcept(L.size()); -// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: the 'empty' method should be used -// CHECK-MESSAGES: :687:18: note: method 'Lazy'::empty() defined here -// CHECK-FIXES: {{^ }}void func() noexcept(!L.empty()); }; Index: clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h =================================================================== --- clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h +++ clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h @@ -33,6 +33,9 @@ } 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; + } }; } // namespace readability Index: clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp +++ clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp @@ -86,6 +86,9 @@ }); return Result; } +AST_MATCHER(CXXConstructExpr, isDefaultConstruction) { + return Node.getConstructor()->isDefaultConstructor(); +} } // namespace ast_matchers namespace tidy { namespace readability { @@ -119,24 +122,16 @@ const auto ValidContainer = qualType( anyOf(ValidContainerNonTemplateType, ValidContainerTemplateType)); - const auto WrongUse = traverse( - TK_AsIs, - anyOf( - hasParent(binaryOperator(isComparisonOperator(), - hasEitherOperand(ignoringImpCasts( - anyOf(integerLiteral(equals(1)), - integerLiteral(equals(0)))))) - .bind("SizeBinaryOp")), - hasParent(implicitCastExpr( - hasImplicitDestinationType(booleanType()), - anyOf(hasParent( - unaryOperator(hasOperatorName("!")).bind("NegOnSize")), - anything()))), - usedInBooleanContext())); + const auto WrongUse = + anyOf(hasParent(binaryOperator( + isComparisonOperator(), + hasEitherOperand(anyOf(integerLiteral(equals(1)), + integerLiteral(equals(0))))) + .bind("SizeBinaryOp")), + usedInBooleanContext()); Finder->addMatcher( - cxxMemberCallExpr(unless(isInTemplateInstantiation()), - on(expr(anyOf(hasType(ValidContainer), + cxxMemberCallExpr(on(expr(anyOf(hasType(ValidContainer), hasType(pointsTo(ValidContainer)), hasType(references(ValidContainer)))) .bind("MemberCallObject")), @@ -160,18 +155,9 @@ .bind("SizeCallExpr"), this); - // Empty constructor matcher. - const auto DefaultConstructor = cxxConstructExpr( - hasDeclaration(cxxConstructorDecl(isDefaultConstructor()))); // Comparison to empty string or empty constructor. const auto WrongComparend = anyOf( - ignoringImpCasts(stringLiteral(hasSize(0))), - ignoringImpCasts(cxxBindTemporaryExpr(has(DefaultConstructor))), - ignoringImplicit(DefaultConstructor), - cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isCopyConstructor())), - has(expr(ignoringImpCasts(DefaultConstructor)))), - cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isMoveConstructor())), - has(expr(ignoringImpCasts(DefaultConstructor)))), + stringLiteral(hasSize(0)), cxxConstructExpr(isDefaultConstruction()), cxxUnresolvedConstructExpr(argumentCountIs(0))); // Match the object being compared. const auto STLArg = @@ -182,7 +168,6 @@ expr(hasType(ValidContainer)).bind("STLObject")); Finder->addMatcher( cxxOperatorCallExpr( - unless(isInTemplateInstantiation()), hasAnyOverloadedOperatorName("==", "!="), anyOf(allOf(hasArgument(0, WrongComparend), hasArgument(1, STLArg)), allOf(hasArgument(0, STLArg), hasArgument(1, WrongComparend))),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits