[llvm-branch-commits] [clang-tools-extra] release/22.x: [clang-tidy] Fix yet another false positive in `readability-redundant-typename` (#184301) (PR #184395)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Mar 3 09:52:01 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: None (llvmbot)

<details>
<summary>Changes</summary>

Backport bf680bd

Requested by: @<!-- -->localspook

---
Full diff: https://github.com/llvm/llvm-project/pull/184395.diff


2 Files Affected:

- (modified) clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp (+1-1) 
- (modified) clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp (+22-3) 


``````````diff
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
index fde7748df31fa..01f9177c248ac 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
@@ -49,7 +49,7 @@ void RedundantTypenameCheck::registerMatchers(MatchFinder *Finder) {
 void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {
   const TypeLoc TL = [&] {
     if (const auto *TL = Result.Nodes.getNodeAs<TypeLoc>("typeLoc"))
-      return TL->getType()->isDependentType() ? TypeLoc() : *TL;
+      return TL->getType()->isInstantiationDependentType() ? TypeLoc() : *TL;
 
     auto TL = *Result.Nodes.getNodeAs<TypeLoc>("dependentTypeLoc");
     while (const TypeLoc Next = TL.getNextTypeLoc())
diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp
index cb58826efbdaa..7ed6ef02a7257 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp
@@ -279,6 +279,7 @@ WHOLE_TYPE_IN_MACRO Macro2;
 WHOLE_DECLARATION_IN_MACRO;
 
 template <typename T> struct Wrapper {};
+
 template <typename T>
 struct ClassWrapper {
   using R = T;
@@ -298,16 +299,34 @@ typename ClassWrapper<T>::R ClassWrapper<T>::g() {
   return {};
 }
 
-template <typename T> struct StructWrapper {};
+template <typename T>
+struct IntWrapper {
+  using R = int;
+  Wrapper<R> f();
+  R g();
+};
+
+template <typename T>
+Wrapper<typename IntWrapper<T>::R> IntWrapper<T>::f() {
+  return {};
+}
+
+template <typename T>
+typename IntWrapper<T>::R IntWrapper<T>::g() {
+// CHECK-MESSAGES-20: :[[@LINE-1]]:1: warning: redundant 'typename' [readability-redundant-typename]
+// CHECK-FIXES-20: IntWrapper<T>::R IntWrapper<T>::g() {
+  return {};
+}
+
 template <typename T>
 class ClassWithNestedStruct {
   struct Nested {};
-  StructWrapper<Nested> f();
+  Wrapper<Nested> f();
   Nested g();
 };
 
 template <typename T>
-StructWrapper<typename ClassWithNestedStruct<T>::Nested> ClassWithNestedStruct<T>::f() {
+Wrapper<typename ClassWithNestedStruct<T>::Nested> ClassWithNestedStruct<T>::f() {
   return {};
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/184395


More information about the llvm-branch-commits mailing list