This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG7dc410cbff28: [clang-tidy] Fix a regression of readability-container-size-empty after the AST… (authored by hokein).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D131390/new/ https://reviews.llvm.org/D131390 Files: clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.cpp 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 @@ -718,3 +718,16 @@ // CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here // CHECK-FIXES: {{^ }}return !(*ptr).empty(); } + +struct TypedefSize { + typedef int size_type; + size_type size() const; + bool empty() const; +}; +void test() { + TypedefSize ts; + if (ts.size() == 0) + ; + // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used + // CHECK-FIXES: {{^ }}if (ts.empty()){{$}} +} 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 @@ AST_MATCHER(CXXConstructExpr, isDefaultConstruction) { return Node.getConstructor()->isDefaultConstructor(); } +AST_MATCHER(QualType, isIntegralType) { + return Node->isIntegralType(Finder->getASTContext()); +} } // namespace ast_matchers namespace tidy { namespace readability { @@ -99,10 +102,9 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) { const auto ValidContainerRecord = cxxRecordDecl(isSameOrDerivedFrom( namedDecl( - has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(), - hasName("size"), - returns(qualType(isInteger(), unless(booleanType()), - unless(elaboratedType())))) + has(cxxMethodDecl( + isConst(), parameterCountIs(0), isPublic(), hasName("size"), + returns(qualType(isIntegralType(), unless(booleanType())))) .bind("size")), has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(), hasName("empty"), returns(booleanType()))
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 @@ -718,3 +718,16 @@ // CHECK-MESSAGES: :9:8: note: method 'vector'::empty() defined here // CHECK-FIXES: {{^ }}return !(*ptr).empty(); } + +struct TypedefSize { + typedef int size_type; + size_type size() const; + bool empty() const; +}; +void test() { + TypedefSize ts; + if (ts.size() == 0) + ; + // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used + // CHECK-FIXES: {{^ }}if (ts.empty()){{$}} +} 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 @@ AST_MATCHER(CXXConstructExpr, isDefaultConstruction) { return Node.getConstructor()->isDefaultConstructor(); } +AST_MATCHER(QualType, isIntegralType) { + return Node->isIntegralType(Finder->getASTContext()); +} } // namespace ast_matchers namespace tidy { namespace readability { @@ -99,10 +102,9 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) { const auto ValidContainerRecord = cxxRecordDecl(isSameOrDerivedFrom( namedDecl( - has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(), - hasName("size"), - returns(qualType(isInteger(), unless(booleanType()), - unless(elaboratedType())))) + has(cxxMethodDecl( + isConst(), parameterCountIs(0), isPublic(), hasName("size"), + returns(qualType(isIntegralType(), unless(booleanType())))) .bind("size")), has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(), hasName("empty"), returns(booleanType()))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits