-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang-tidy] Fix false positive in readability-redundant-typename
#170034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zeyi2
wants to merge
2
commits into
llvm:main
Choose a base branch
from
zeyi2:fix-redundant-typename
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18
−2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-clang-tidy Author: mitchell (zeyi2) ChangesCloses #169166 Full diff: https://github.com/llvm/llvm-project/pull/170034.diff 3 Files Affected:
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]
|
Member
|
@llvm/pr-subscribers-clang-tools-extra Author: mitchell (zeyi2) ChangesCloses #169166 Full diff: https://github.com/llvm/llvm-project/pull/170034.diff 3 Files Affected:
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]
|
zwuis
reviewed
Nov 30, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #169166