[clang-tools-extra] [clang-tidy] Fix yet another false positive in `readability-redundant-typename` (PR #184301)
Victor Chernyakin via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 3 00:57:37 PST 2026
https://github.com/localspook created https://github.com/llvm/llvm-project/pull/184301
Fixes #184083.
I plan to backport this, so no release note.
>From de43a1cf0ea31710f1b875a010e60567d9d6fdf9 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin <chernyakin.victor.j at outlook.com>
Date: Tue, 3 Mar 2026 00:55:03 -0800
Subject: [PATCH] [clang-tidy] Fix yet another false positive in
`readability-redundant-typename`
---
.../readability/RedundantTypenameCheck.cpp | 2 +-
.../readability/redundant-typename.cpp | 25 ++++++++++++++++---
2 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
index 676dc9c7a1582..77ef2b8622c93 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
@@ -50,7 +50,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 138e616774355..56ff9813cd6ae 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
@@ -283,6 +283,7 @@ WHOLE_TYPE_IN_MACRO Macro2;
WHOLE_DECLARATION_IN_MACRO;
template <typename T> struct Wrapper {};
+
template <typename T>
struct ClassWrapper {
using R = T;
@@ -302,16 +303,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 cfe-commits
mailing list