[clang-tidy] Fix false positive in readability-redundant-typename (#170034)

Closes #169166

---------

Co-authored-by: Victor Chernyakin <chernyakin.victor.j@outlook.com>
This commit is contained in:
mitchell
2025-12-03 18:41:45 +08:00
committed by GitHub
parent f17abc280c
commit 49774448d6
2 changed files with 28 additions and 2 deletions

View File

@@ -47,6 +47,9 @@ void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {
const SourceLocation ElaboratedKeywordLoc = [&] {
if (const auto *NonDependentTypeLoc =
Result.Nodes.getNodeAs<TypeLoc>("nonDependentTypeLoc")) {
if (NonDependentTypeLoc->getType()->isDependentType())
return SourceLocation();
if (const auto TL = NonDependentTypeLoc->getAs<TypedefTypeLoc>())
return TL.getElaboratedKeywordLoc();
@@ -59,8 +62,7 @@ void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto TL =
NonDependentTypeLoc->getAs<TemplateSpecializationTypeLoc>())
if (!TL.getType()->isDependentType())
return TL.getElaboratedKeywordLoc();
return TL.getElaboratedKeywordLoc();
} else {
TypeLoc InnermostTypeLoc =
*Result.Nodes.getNodeAs<TypeLoc>("dependentTypeLoc");

View File

@@ -267,3 +267,27 @@ WHOLE_TYPE_IN_MACRO Macro2;
#define WHOLE_DECLARATION_IN_MACRO typename NotDependent::R Macro3
WHOLE_DECLARATION_IN_MACRO;
template <typename T> struct Wrapper {};
template <typename T>
struct ClassWrapper {
using R = T;
Wrapper<R> f();
};
template <typename T>
Wrapper<typename ClassWrapper<T>::R> ClassWrapper<T>::f() {
return {};
}
template <typename T> struct StructWrapper {};
template <typename T>
class ClassWithNestedStruct {
struct Nested {};
StructWrapper<Nested> f();
};
template <typename T>
StructWrapper<typename ClassWithNestedStruct<T>::Nested> ClassWithNestedStruct<T>::f() {
return {};
}