llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-tidy Author: Piotr Zegar (PiotrZSL) <details> <summary>Changes</summary> 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. --- Full diff: https://github.com/llvm/llvm-project/pull/150290.diff 3 Files Affected: - (modified) clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp (+3-2) - (modified) clang-tools-extra/docs/ReleaseNotes.rst (+5-1) - (modified) clang-tools-extra/test/clang-tidy/checkers/portability/template-virtual-member-function.cpp (+17) ``````````diff 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..4626365699888 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 PR139031 { + +template<typename T> +struct Base { + virtual void foo() = 0; +}; + +struct Derived : public Base<int> { + void foo() {} +}; + +void test() { + Derived{}.foo(); +} + +} `````````` </details> https://github.com/llvm/llvm-project/pull/150290 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits