llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: Victor Chernyakin (localspook)

<details>
<summary>Changes</summary>

Fixes #<!-- -->175475.

This PR depends on #<!-- -->175473 (this is a sort of ad-hoc stack)

---
Full diff: https://github.com/llvm/llvm-project/pull/175477.diff


2 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp (+16-12) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/redundant-typename.cpp 
(+40) 


``````````diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
index 0816625b1937d..676dc9c7a1582 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantTypenameCheck.cpp
@@ -25,22 +25,26 @@ void RedundantTypenameCheck::registerMatchers(MatchFinder 
*Finder) {
   if (!getLangOpts().CPlusPlus20)
     return;
 
-  const auto InImplicitTypenameContext = anyOf(
-      hasParent(decl(anyOf(
-          typedefNameDecl(), templateTypeParmDecl(), nonTypeTemplateParmDecl(),
-          friendDecl(), fieldDecl(),
-          varDecl(hasDeclContext(anyOf(namespaceDecl(), 
translationUnitDecl())),
-                  unless(parmVarDecl())),
-          parmVarDecl(hasParent(expr(requiresExpr()))),
-          parmVarDecl(hasParent(typeLoc(hasParent(decl(
-              anyOf(cxxMethodDecl(), hasParent(friendDecl()),
+  const auto InImplicitTypenameContext =
+      anyOf(hasParent(decl(anyOf(
+                typedefNameDecl(), templateTypeParmDecl(),
+                nonTypeTemplateParmDecl(), friendDecl(), fieldDecl(),
+                parmVarDecl(hasParent(expr(requiresExpr()))),
+                parmVarDecl(hasParent(typeLoc(hasParent(decl(anyOf(
+                    cxxMethodDecl(), hasParent(friendDecl()),
                     functionDecl(has(nestedNameSpecifier())),
                     cxxDeductionGuideDecl(hasDeclContext(recordDecl())))))))),
-          // Match return types.
-          functionDecl(unless(cxxConversionDecl()))))),
-      hasParent(expr(anyOf(cxxNamedCastExpr(), cxxNewExpr()))));
+                // Match return types.
+                functionDecl(unless(cxxConversionDecl()))))),
+            hasParent(expr(anyOf(cxxNamedCastExpr(), cxxNewExpr()))));
   Finder->addMatcher(
       typeLoc(InImplicitTypenameContext).bind("dependentTypeLoc"), this);
+  Finder->addMatcher(
+      varDecl(hasDeclContext(anyOf(namespaceDecl(), translationUnitDecl(),
+                                   cxxRecordDecl())),
+              unless(parmVarDecl()),
+              hasTypeLoc(typeLoc().bind("dependentTypeLoc"))),
+      this);
 }
 
 void RedundantTypenameCheck::check(const MatchFinder::MatchResult &Result) {
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 96bd7b6412724..138e616774355 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
@@ -157,6 +157,16 @@ typename T::R v = typename T::R();
 // CHECK-MESSAGES-20: :[[@LINE-1]]:1: warning: redundant 'typename' 
[readability-redundant-typename]
 // CHECK-FIXES-20: T::R v = typename T::R();
 
+template <typename T, typename>
+typename T::R PartiallySpecializedVariable = true;
+// CHECK-MESSAGES-20: :[[@LINE-1]]:1: warning: redundant 'typename' 
[readability-redundant-typename]
+// CHECK-FIXES-20: T::R PartiallySpecializedVariable = true;
+
+template <typename T>
+typename T::R PartiallySpecializedVariable<T, typename T::R> = false;
+// CHECK-MESSAGES-20: :[[@LINE-1]]:1: warning: redundant 'typename' 
[readability-redundant-typename]
+// CHECK-FIXES-20: T::R PartiallySpecializedVariable<T, typename T::R> = false;
+
 #endif // __cplusplus >= 201402L
 
 template <typename T>
@@ -208,6 +218,10 @@ class A {
   // 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
@@ -307,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

``````````

</details>


https://github.com/llvm/llvm-project/pull/175477
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to