[clang-tidy] Fix false negatives around static data members in readability-redundant-typename (#175477)

Fixes #175475.
This commit is contained in:
Victor Chernyakin 2026-01-14 01:28:47 -07:00 committed by GitHub
parent 17aa32c243
commit aaa99a3e9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View File

@ -40,7 +40,8 @@ void RedundantTypenameCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
typeLoc(InImplicitTypenameContext).bind("dependentTypeLoc"), this);
Finder->addMatcher(
varDecl(hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl())),
varDecl(hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl(),
cxxRecordDecl())),
unless(parmVarDecl()),
hasTypeLoc(typeLoc().bind("dependentTypeLoc"))),
this);

View File

@ -218,6 +218,10 @@ public:
// CHECK-MESSAGES-20: :[[@LINE-1]]:3: warning: redundant 'typename' [readability-redundant-typename]
// CHECK-FIXES-20: T::R v;
static typename T::R StaticDataMember;
// CHECK-MESSAGES-20: :[[@LINE-1]]:10: warning: redundant 'typename' [readability-redundant-typename]
// CHECK-FIXES-20: static T::R StaticDataMember;
typename T::R
// CHECK-MESSAGES-20: :[[@LINE-1]]:3: warning: redundant 'typename' [readability-redundant-typename]
// CHECK-FIXES-20: T::R
@ -317,3 +321,29 @@ typename ClassWithNestedStruct<T>::Nested ClassWithNestedStruct<T>::g() {
// CHECK-FIXES-20: ClassWithNestedStruct<T>::Nested ClassWithNestedStruct<T>::g() {
return {};
}
#if __cplusplus >= 201402L
struct Foo {
template <typename T, typename>
static typename T::R PartiallySpecializedDataMember;
// CHECK-MESSAGES-20: :[[@LINE-1]]:10: warning: redundant 'typename' [readability-redundant-typename]
// CHECK-FIXES-20: static T::R PartiallySpecializedDataMember;
template <typename T>
static typename T::R PartiallySpecializedDataMember<T, typename T::R> = false;
// CHECK-MESSAGES-20: :[[@LINE-1]]:10: warning: redundant 'typename' [readability-redundant-typename]
// CHECK-FIXES-20: static T::R PartiallySpecializedDataMember<T, typename T::R> = false;
};
template <typename T, typename>
typename T::R Foo::PartiallySpecializedDataMember = true;
// CHECK-MESSAGES-20: :[[@LINE-1]]:1: warning: redundant 'typename' [readability-redundant-typename]
// CHECK-FIXES-20: T::R Foo::PartiallySpecializedDataMember = true;
template <typename T>
typename T::R Foo::PartiallySpecializedDataMember<T, typename T::V> = false;
// CHECK-MESSAGES-20: :[[@LINE-1]]:1: warning: redundant 'typename' [readability-redundant-typename]
// CHECK-FIXES-20: T::R Foo::PartiallySpecializedDataMember<T, typename T::V> = false;
#endif // __cplusplus >= 201402L