https://github.com/zeyi2 updated https://github.com/llvm/llvm-project/pull/185875
>From 9bea273bda890c0b7d591f8a5fd8f84b6c6c18f3 Mon Sep 17 00:00:00 2001 From: Tom James <[email protected]> Date: Wed, 11 Mar 2026 13:15:35 +0000 Subject: [PATCH 1/4] [clang-tidy] Correctly ignore function templates in derived-method-shadowing-base-method (#185741) --- .../bugprone/DerivedMethodShadowingBaseMethodCheck.cpp | 6 +++++- .../bugprone/derived-method-shadowing-base-method.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp index 7c5867619cf4e..a49dd0c0e2622 100644 --- a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp @@ -83,6 +83,10 @@ AST_MATCHER(CXXMethodDecl, nameCollidesWithMethodInBase) { // similar matchers are used elsewhere in LLVM AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); } +AST_MATCHER(CXXMethodDecl, isTemplate) { + return Node.getDescribedFunctionTemplate() != nullptr; +} + } // namespace DerivedMethodShadowingBaseMethodCheck::DerivedMethodShadowingBaseMethodCheck( @@ -97,7 +101,7 @@ void DerivedMethodShadowingBaseMethodCheck::registerMatchers( cxxConstructorDecl(), isOverride(), isPrivate(), // isFinal(), //included with isOverride, // Templates are not handled yet - ast_matchers::isTemplateInstantiation(), + isTemplate(), ast_matchers::isTemplateInstantiation(), ast_matchers::isExplicitTemplateSpecialization())), ofClass(cxxRecordDecl(isDerivedFrom(cxxRecordDecl())) .bind("derived_class")), diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/derived-method-shadowing-base-method.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/derived-method-shadowing-base-method.cpp index c22598d84d1b2..c615646251470 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/derived-method-shadowing-base-method.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/derived-method-shadowing-base-method.cpp @@ -137,3 +137,10 @@ class Q : public Base void methodWithArg(MyInt *I); void methodWithArg(MyInt const* I); }; + +class R: public Base +{ +public: + template <typename T> + Base* getThis(); +}; >From aa18a7131e16bc80b6af1138ec89fba3105b4b75 Mon Sep 17 00:00:00 2001 From: Tom James <[email protected]> Date: Fri, 13 Mar 2026 16:36:44 +0000 Subject: [PATCH 2/4] fixup! [clang-tidy] Correctly ignore function templates in derived-method-shadowing-base-method (#185741) --- clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 6995e02247861..16eefa327de76 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -102,6 +102,9 @@ Improvements to clang-tidy manages the creation of temporary header files and ensures that diagnostics and fixes are verified for the specified headers. +- bugprone-derived-method-shadowing-base-method now correctly ignores function + templates. + New checks ^^^^^^^^^^ >From 419eaf69d2fe93a6e4440af3b71facc5d583f593 Mon Sep 17 00:00:00 2001 From: Zeyi Xu <[email protected]> Date: Mon, 23 Mar 2026 16:13:34 +0800 Subject: [PATCH 3/4] address zwuis's suggestion --- .../bugprone/DerivedMethodShadowingBaseMethodCheck.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp index fc34dd4fa8c80..904685cb8416d 100644 --- a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp @@ -98,7 +98,7 @@ void DerivedMethodShadowingBaseMethodCheck::registerMatchers( unless(anyOf(isOutOfLine(), isStaticStorageClass(), isImplicit(), cxxConstructorDecl(), isOverride(), isPrivate(), // isFinal(), //included with isOverride, - // Templates are not handled yet + // TODO: Templates are not handled yet isTemplate(), ast_matchers::isTemplateInstantiation(), ast_matchers::isExplicitTemplateSpecialization())), ofClass(cxxRecordDecl(isDerivedFrom(cxxRecordDecl())) >From db117e4ca4b9084f178db6b103ffc7709cfb96a0 Mon Sep 17 00:00:00 2001 From: Zeyi Xu <[email protected]> Date: Mon, 23 Mar 2026 16:13:59 +0800 Subject: [PATCH 4/4] Update clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
