flx created this revision. flx added reviewers: ymandel, courbet, aaron.ballman. Herald added subscribers: carlosgalvezp, xazax.hun. flx requested review of this revision. Herald added a project: clang-tools-extra. Herald added a subscriber: cfe-commits.
The matching did not work correctly for pointer and reference types. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D114212 Files: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp +++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp @@ -58,3 +58,13 @@ const auto E = C.secretlyMutates(); E.constMethod(); } + +void excludedConstIncorrectTypeAsPointer(ConstInCorrectType *C) { + const auto E = C->secretlyMutates(); + E.constMethod(); +} + +void excludedConstIncorrectTypeAsReference(const ConstInCorrectType &C) { + const auto E = C.secretlyMutates(); + E.constMethod(); +} Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp =================================================================== --- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp +++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp @@ -87,11 +87,9 @@ callee(cxxMethodDecl( returns(hasCanonicalType(matchers::isReferenceToConst()))) .bind(MethodDeclId)), - on(declRefExpr(to( - varDecl( - unless(hasType(qualType(hasCanonicalType(hasDeclaration(namedDecl( - matchers::matchesAnyListedName(ExcludedContainerTypes)))))))) - .bind(ObjectArgId))))); + on(declRefExpr(to(varDecl().bind(ObjectArgId)))), + thisPointerType(namedDecl( + unless(matchers::matchesAnyListedName(ExcludedContainerTypes))))); } AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) {
Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp +++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization-excluded-container-types.cpp @@ -58,3 +58,13 @@ const auto E = C.secretlyMutates(); E.constMethod(); } + +void excludedConstIncorrectTypeAsPointer(ConstInCorrectType *C) { + const auto E = C->secretlyMutates(); + E.constMethod(); +} + +void excludedConstIncorrectTypeAsReference(const ConstInCorrectType &C) { + const auto E = C.secretlyMutates(); + E.constMethod(); +} Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp =================================================================== --- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp +++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp @@ -87,11 +87,9 @@ callee(cxxMethodDecl( returns(hasCanonicalType(matchers::isReferenceToConst()))) .bind(MethodDeclId)), - on(declRefExpr(to( - varDecl( - unless(hasType(qualType(hasCanonicalType(hasDeclaration(namedDecl( - matchers::matchesAnyListedName(ExcludedContainerTypes)))))))) - .bind(ObjectArgId))))); + on(declRefExpr(to(varDecl().bind(ObjectArgId)))), + thisPointerType(namedDecl( + unless(matchers::matchesAnyListedName(ExcludedContainerTypes))))); } AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits