[clang-tools-extra] [clang-tidy] Fix false positive in `readability-redundant-typename` (PR #170034)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 30 05:10:29 PST 2025
https://github.com/zeyi2 created https://github.com/llvm/llvm-project/pull/170034
Closes #169166
>From e8bc35d273950cc6d5f1e947db1d34741de52432 Mon Sep 17 00:00:00 2001
From: mtx <mitchell.xu2 at gmail.com>
Date: Sun, 30 Nov 2025 20:54:12 +0800
Subject: [PATCH] [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]
More information about the cfe-commits
mailing list