[llvm-branch-commits] [clang-tools-extra] c1fe91b - [clang-tidy] Fix yet another false positive in `readability-redundant-typename` (#184301)

Douglas Yung via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Mar 6 09:21:07 PST 2026


Author: Victor Chernyakin
Date: 2026-03-06T17:20:48Z
New Revision: c1fe91b2cd14130430be6426446ab0923b55e073

URL: https://github.com/llvm/llvm-project/commit/c1fe91b2cd14130430be6426446ab0923b55e073
DIFF: https://github.com/llvm/llvm-project/commit/c1fe91b2cd14130430be6426446ab0923b55e073.diff

LOG: [clang-tidy] Fix yet another false positive in `readability-redundant-typename` (#184301)

Fixes #184083.

(cherry picked from commit bf680bdf13499860a552f991bb9d11b2b52b8ea8)

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
    clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp

Removed: 
    


################################################################################
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 {};
 }
 


        


More information about the llvm-branch-commits mailing list