https://github.com/isuckatcs updated https://github.com/llvm/llvm-project/pull/211122
>From 60b0cba007874a498e9646efa49f190ae24c6553 Mon Sep 17 00:00:00 2001 From: isuckatcs <[email protected]> Date: Wed, 22 Jul 2026 00:09:04 +0200 Subject: [PATCH] [clang-tidy] reword the diag messages of `TemplateVirtualMemberFunctionCheck` The previous diag message caused a lot of confusion for users, as the wording made it unclear what the problem is, and how to fix it. This change ensures that the diag message explicitly states the issue and recommends a fix for it. Fixes #153155 Fixes #206767 --- .../TemplateVirtualMemberFunctionCheck.cpp | 9 +++--- clang-tools-extra/docs/ReleaseNotes.rst | 4 +++ .../template-virtual-member-function.cpp | 28 +++++++++---------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp index bf3173dc993e2..92a2d4314d183 100644 --- a/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp +++ b/clang-tools-extra/clang-tidy/portability/TemplateVirtualMemberFunctionCheck.cpp @@ -35,11 +35,12 @@ void TemplateVirtualMemberFunctionCheck::check( const auto *MethodDecl = Result.Nodes.getNodeAs<CXXMethodDecl>("method"); diag(MethodDecl->getLocation(), - "unspecified virtual member function instantiation; the virtual " - "member function is not instantiated but it might be with a " - "different compiler"); + "it is unspecified whether or not an implementation implicitly " + "instantiates a virtual member function of a class template if the " + "virtual member function would not otherwise be instantiated; consider " + "using or removing the virtual member function for better portability"); diag(ImplicitSpecialization->getPointOfInstantiation(), - "template instantiated here", DiagnosticIDs::Note); + "class template instantiated here", DiagnosticIDs::Note); } } // namespace clang::tidy::portability diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 69c3bcf67b8db..8397c628d4cf1 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -94,6 +94,10 @@ Improvements to clang-query Improvements to clang-tidy -------------------------- +- Improved :doc:`portability-template-virtual-member-function + <clang-tidy/checks/portability/template-virtual-member-function>` check to + make it easier to understand what the issue is and how to fix it. + New 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 2a67b79cb358a..adc1f48fecf32 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 @@ -6,14 +6,14 @@ struct CrossPlatformError { static void used() {} - // CHECK-MESSAGES: [[#@LINE+1]]:18: warning: unspecified virtual member function instantiation + // CHECK-MESSAGES: [[#@LINE+1]]:18: warning: it is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated; consider using or removing the virtual member function for better portability virtual void unused() { T MSVCError = this; }; }; int main() { - // CHECK-MESSAGES: [[#@LINE+1]]:5: note: template instantiated here + // CHECK-MESSAGES: [[#@LINE+1]]:5: note: class template instantiated here CrossPlatformError<int>::used(); return 0; } @@ -26,14 +26,14 @@ struct CrossPlatformError { static void used() {} - // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: unspecified virtual member function instantiation - // CHECK-MESSAGES: [[#@LINE+13]]:5: note: template instantiated here + // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: it is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated; consider using or removing the virtual member function for better portability + // CHECK-MESSAGES: [[#@LINE+13]]:5: note: class template instantiated here virtual void unused() { T MSVCError = this; }; - // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: unspecified virtual member function instantiation - // CHECK-MESSAGES: [[#@LINE+7]]:5: note: template instantiated here + // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: it is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated; consider using or removing the virtual member function for better portability + // CHECK-MESSAGES: [[#@LINE+7]]:5: note: class template instantiated here virtual void unused2() { T MSVCError = this; }; @@ -48,8 +48,8 @@ int main() { namespace UninstantiatedVirtualDestructor { template<typename T> struct CrossPlatformError { - // CHECK-MESSAGES: [[#@LINE+2]]:13: warning: unspecified virtual member function instantiation - // CHECK-MESSAGES: [[#@LINE+9]]:5: note: template instantiated here + // CHECK-MESSAGES: [[#@LINE+2]]:13: warning: it is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated; consider using or removing the virtual member function for better portability + // CHECK-MESSAGES: [[#@LINE+9]]:5: note: class template instantiated here virtual ~CrossPlatformError() { T MSVCError = this; }; @@ -70,8 +70,8 @@ struct CrossPlatformError { static void used() {} - // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: unspecified virtual member function instantiation - // CHECK-MESSAGES: [[#@LINE+7]]:5: note: template instantiated here + // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: it is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated; consider using or removing the virtual member function for better portability + // CHECK-MESSAGES: [[#@LINE+7]]:5: note: class template instantiated here virtual void unused() { T MSVCError = this; }; @@ -91,8 +91,8 @@ template <typename T> struct CrossPlatformError { static void used() {} - // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: unspecified virtual member function instantiation - // CHECK-MESSAGES: [[#@LINE+5]]:5: note: template instantiated here + // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: it is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated; consider using or removing the virtual member function for better portability + // CHECK-MESSAGES: [[#@LINE+5]]:5: note: class template instantiated here virtual void unused(){}; }; @@ -143,8 +143,8 @@ struct CrossPlatformError<int, U>{ static void used() {} - // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: unspecified virtual member function instantiation - // CHECK-MESSAGES: [[#@LINE+7]]:5: note: template instantiated here + // CHECK-MESSAGES: [[#@LINE+2]]:18: warning: it is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated; consider using or removing the virtual member function for better portability + // CHECK-MESSAGES: [[#@LINE+7]]:5: note: class template instantiated here virtual void unused() { U MSVCError = this; }; _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
