Skip to content

Commit 4977444

Browse files
zeyi2localspook
andauthored
[clang-tidy] Fix false positive in readability-redundant-typename (#170034)
Closes #169166 --------- Co-authored-by: Victor Chernyakin <chernyakin.victor.j@outlook.com>
1 parent f17abc2 commit 4977444

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {
4747
const SourceLocation ElaboratedKeywordLoc = [&] {
4848
if (const auto *NonDependentTypeLoc =
4949
Result.Nodes.getNodeAs<TypeLoc>("nonDependentTypeLoc")) {
50+
if (NonDependentTypeLoc->getType()->isDependentType())
51+
return SourceLocation();
52+
5053
if (const auto TL = NonDependentTypeLoc->getAs<TypedefTypeLoc>())
5154
return TL.getElaboratedKeywordLoc();
5255

@@ -59,8 +62,7 @@ void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {
5962

6063
if (const auto TL =
6164
NonDependentTypeLoc->getAs<TemplateSpecializationTypeLoc>())
62-
if (!TL.getType()->isDependentType())
63-
return TL.getElaboratedKeywordLoc();
65+
return TL.getElaboratedKeywordLoc();
6466
} else {
6567
TypeLoc InnermostTypeLoc =
6668
*Result.Nodes.getNodeAs<TypeLoc>("dependentTypeLoc");

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,27 @@ WHOLE_TYPE_IN_MACRO Macro2;
267267

268268
#define WHOLE_DECLARATION_IN_MACRO typename NotDependent::R Macro3
269269
WHOLE_DECLARATION_IN_MACRO;
270+
271+
template <typename T> struct Wrapper {};
272+
template <typename T>
273+
struct ClassWrapper {
274+
using R = T;
275+
Wrapper<R> f();
276+
};
277+
278+
template <typename T>
279+
Wrapper<typename ClassWrapper<T>::R> ClassWrapper<T>::f() {
280+
return {};
281+
}
282+
283+
template <typename T> struct StructWrapper {};
284+
template <typename T>
285+
class ClassWithNestedStruct {
286+
struct Nested {};
287+
StructWrapper<Nested> f();
288+
};
289+
290+
template <typename T>
291+
StructWrapper<typename ClassWithNestedStruct<T>::Nested> ClassWithNestedStruct<T>::f() {
292+
return {};
293+
}

0 commit comments

Comments
 (0)