Author: Piotr Zegar Date: 2025-07-23T21:51:58+02:00 New Revision: 478130545bc41a8bb80304e5d931559a9d2b6171
URL: https://github.com/llvm/llvm-project/commit/478130545bc41a8bb80304e5d931559a9d2b6171 DIFF: https://github.com/llvm/llvm-project/commit/478130545bc41a8bb80304e5d931559a9d2b6171.diff LOG: [clang-tidy] Ignore pure-virtual in portability-template... (#150290) Ignore pure virtual member functions in portability-template-virtual-member-function check. Those functions will be represented in vtable as __cxa_pure_virtual or something similar. Fixes #139031. Added: Modified: clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp index 9c2f27f01f184..aaa23367a3825 100644 --- a/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp +++ b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp @@ -18,10 +18,11 @@ AST_MATCHER(CXXMethodDecl, isUsed) { return Node.isUsed(); } void TemplateVirtualMemberFunctionCheck::registerMatchers(MatchFinder *Finder) { Finder->addMatcher( - cxxMethodDecl(ofClass(classTemplateSpecializationDecl( + cxxMethodDecl(isVirtual(), + ofClass(classTemplateSpecializationDecl( unless(isExplicitTemplateSpecialization())) .bind("specialization")), - isVirtual(), unless(isUsed()), + unless(isUsed()), unless(isPure()), unless(cxxDestructorDecl(isDefaulted()))) .bind("method"), this); diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index c5f756aeee6eb..c75d9ca71cad7 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -121,7 +121,11 @@ Changes in existing checks - Improved :doc:`misc-header-include-cycle <clang-tidy/checks/misc/header-include-cycle>` check performance. - + +- Improved :doc:`portability-template-virtual-member-function + <clang-tidy/checks/portability/template-virtual-member-function>` check to + avoid false positives on pure virtual member functions. + Removed checks ^^^^^^^^^^^^^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp b/clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp index 94786ae93dd3f..2a67b79cb358a 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp @@ -171,3 +171,20 @@ struct NoInstantiation<int, U>{ }; }; } // namespace PartialSpecializationNoInstantiation + +namespace PureVirtual { + +template<typename T> +struct Base { + virtual void foo() = 0; +}; + +struct Derived : public Base<int> { + void foo() {} +}; + +void test() { + Derived{}.foo(); +} + +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits