https://github.com/zeyi2 updated 
https://github.com/llvm/llvm-project/pull/170034

>From e8bc35d273950cc6d5f1e947db1d34741de52432 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sun, 30 Nov 2025 20:54:12 +0800
Subject: [PATCH 1/4] [clang-tidy] Fix false positive in
 readability-redundant-typename

---
 .../readability/RedundantTypenameCheck.cpp         |  6 ++++--
 clang-tools-extra/docs/ReleaseNotes.rst            |  4 ++++
 .../checkers/readability/redundant-typename.cpp    | 14 ++++++++++++++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
index a4edd2b46b86b..feb09086f3cfd 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
@@ -47,8 +47,10 @@ void RedundantTypenameCheck::check(const 
MatchFinder::MatchResult &Result) {
   const SourceLocation ElaboratedKeywordLoc = [&] {
     if (const auto *NonDependentTypeLoc =
             Result.Nodes.getNodeAs<TypeLoc>("nonDependentTypeLoc")) {
-      if (const auto TL = NonDependentTypeLoc->getAs<TypedefTypeLoc>())
-        return TL.getElaboratedKeywordLoc();
+      if (const auto TL = NonDependentTypeLoc->getAs<TypedefTypeLoc>()) {
+        if (!TL.getType()->isDependentType())
+          return TL.getElaboratedKeywordLoc();
+      }
 
       if (const auto TL = NonDependentTypeLoc->getAs<TagTypeLoc>())
         return TL.getElaboratedKeywordLoc();
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a6f80e3721db1..19c5db0ac08be 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -547,6 +547,10 @@ Changes in existing checks
   <clang-tidy/checks/readability/qualified-auto>` check by adding the option
   `IgnoreAliasing`, that allows not looking at underlying types of type 
aliases.
 
+- Improved :doc:`readability-redundant-typename
+  <clang-tidy/checks/readability/redundant-typename>` check to correctly
+  handle dependent types in type aliases.
+
 - Improved :doc:`readability-uppercase-literal-suffix
   <clang-tidy/checks/readability/uppercase-literal-suffix>` check to recognize
   literal suffixes added in C++23 and C23.
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 2efafd1a9a649..35e239bf5694d 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
@@ -267,3 +267,17 @@ WHOLE_TYPE_IN_MACRO Macro2;
 
 #define WHOLE_DECLARATION_IN_MACRO typename NotDependent::R Macro3
 WHOLE_DECLARATION_IN_MACRO;
+
+template<typename T> struct ListWrapper {};
+template<typename T>
+class ClassWrapper {
+public:
+    using Argument = ListWrapper<T>;
+    ListWrapper<Argument> arguments;
+    ListWrapper<Argument> getArguments() const;
+};
+template<typename T>
+ListWrapper<typename ClassWrapper<T>::Argument> 
ClassWrapper<T>::getArguments() const {
+    return arguments;
+}
+// CHECK-NOT: warning: redundant 'typename' [readability-redundant-typename]

>From 80bf0d61236565848cd5a8cd4b6a73f265f55051 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Sun, 30 Nov 2025 23:48:33 +0800
Subject: [PATCH 2/4] Remove docs

---
 clang-tools-extra/docs/ReleaseNotes.rst | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 19c5db0ac08be..a6f80e3721db1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -547,10 +547,6 @@ Changes in existing checks
   <clang-tidy/checks/readability/qualified-auto>` check by adding the option
   `IgnoreAliasing`, that allows not looking at underlying types of type 
aliases.
 
-- Improved :doc:`readability-redundant-typename
-  <clang-tidy/checks/readability/redundant-typename>` check to correctly
-  handle dependent types in type aliases.
-
 - Improved :doc:`readability-uppercase-literal-suffix
   <clang-tidy/checks/readability/uppercase-literal-suffix>` check to recognize
   literal suffixes added in C++23 and C23.

>From 8bbc7b916ae779320d917ef7bba0b4a26111efa8 Mon Sep 17 00:00:00 2001
From: mitchell <[email protected]>
Date: Wed, 3 Dec 2025 13:03:06 +0800
Subject: [PATCH 3/4] Apply suggestions from code review

Fix testcases

Co-authored-by: Victor Chernyakin <[email protected]>
---
 .../readability/redundant-typename.cpp        | 20 +++++++++----------
 1 file changed, 9 insertions(+), 11 deletions(-)

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 35e239bf5694d..84293fb26336b 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
@@ -268,16 +268,14 @@ WHOLE_TYPE_IN_MACRO Macro2;
 #define WHOLE_DECLARATION_IN_MACRO typename NotDependent::R Macro3
 WHOLE_DECLARATION_IN_MACRO;
 
-template<typename T> struct ListWrapper {};
-template<typename T>
-class ClassWrapper {
-public:
-    using Argument = ListWrapper<T>;
-    ListWrapper<Argument> arguments;
-    ListWrapper<Argument> getArguments() const;
+template <typename T> struct Wrapper {};
+template <typename T>
+struct ClassWrapper {
+    using R = T;
+    Wrapper<R> f();
 };
-template<typename T>
-ListWrapper<typename ClassWrapper<T>::Argument> 
ClassWrapper<T>::getArguments() const {
-    return arguments;
+
+template <typename T>
+Wrapper<typename ClassWrapper<T>::R> ClassWrapper<T>::f() {
+    return {};
 }
-// CHECK-NOT: warning: redundant 'typename' [readability-redundant-typename]

>From e7dbdf2ac052a2382814eece9c75b6e916b428f5 Mon Sep 17 00:00:00 2001
From: mtx <[email protected]>
Date: Wed, 3 Dec 2025 13:33:14 +0800
Subject: [PATCH 4/4] Fix implementation and add new tests

---
 .../readability/RedundantTypenameCheck.cpp           | 12 ++++++------
 .../checkers/readability/redundant-typename.cpp      | 12 ++++++++++++
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
index feb09086f3cfd..5f2519ce9d5c3 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
@@ -47,10 +47,11 @@ void RedundantTypenameCheck::check(const 
MatchFinder::MatchResult &Result) {
   const SourceLocation ElaboratedKeywordLoc = [&] {
     if (const auto *NonDependentTypeLoc =
             Result.Nodes.getNodeAs<TypeLoc>("nonDependentTypeLoc")) {
-      if (const auto TL = NonDependentTypeLoc->getAs<TypedefTypeLoc>()) {
-        if (!TL.getType()->isDependentType())
-          return TL.getElaboratedKeywordLoc();
-      }
+      if (NonDependentTypeLoc->getType()->isDependentType())
+        return SourceLocation();
+
+      if (const auto TL = NonDependentTypeLoc->getAs<TypedefTypeLoc>())
+        return TL.getElaboratedKeywordLoc();
 
       if (const auto TL = NonDependentTypeLoc->getAs<TagTypeLoc>())
         return TL.getElaboratedKeywordLoc();
@@ -61,8 +62,7 @@ void RedundantTypenameCheck::check(const 
MatchFinder::MatchResult &Result) {
 
       if (const auto TL =
               NonDependentTypeLoc->getAs<TemplateSpecializationTypeLoc>())
-        if (!TL.getType()->isDependentType())
-          return TL.getElaboratedKeywordLoc();
+        return TL.getElaboratedKeywordLoc();
     } else {
       TypeLoc InnermostTypeLoc =
           *Result.Nodes.getNodeAs<TypeLoc>("dependentTypeLoc");
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 84293fb26336b..e8fcd9bcd5731 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,3 +279,15 @@ template <typename T>
 Wrapper<typename ClassWrapper<T>::R> ClassWrapper<T>::f() {
     return {};
 }
+
+template <typename T> struct StructWrapper {};
+template <typename T>
+class ClassWithNestedStruct {
+  struct Nested {};
+  StructWrapper<Nested> f();
+};
+
+template <typename T>
+StructWrapper<typename ClassWithNestedStruct<T>::Nested> 
ClassWithNestedStruct<T>::f() {
+  return {};
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to