[clang-tools-extra] [clang-tidy] Correctly ignore function templates in derived-method-shadowing-base-method (#185741) (PR #185875)
Zeyi Xu via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 23 00:59:33 PDT 2026
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 <tom.james at siemens.com>
Date: Wed, 11 Mar 2026 13:15:35 +0000
Subject: [PATCH 1/2] [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 <tom.james at siemens.com>
Date: Fri, 13 Mar 2026 16:36:44 +0000
Subject: [PATCH 2/2] 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
^^^^^^^^^^
More information about the cfe-commits
mailing list