[PATCH] D78139: [clang-tidy] modernize-use-using: Fix broken fixit with 'template' keyword
Matthias Gehre via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 15 11:30:34 PDT 2020
mgehre updated this revision to Diff 257774.
mgehre marked an inline comment as done.
mgehre added a comment.
Implement review comments (Thanks!)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78139/new/
https://reviews.llvm.org/D78139
Files:
clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
clang/lib/AST/NestedNameSpecifier.cpp
clang/lib/AST/TypePrinter.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
Index: clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
===================================================================
--- clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
+++ clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
@@ -109,9 +109,9 @@
struct G { template<typename T> static T temp; };
template<typename T> requires requires { typename T::template temp<int>; }
-// expected-note at -1{{because 'typename T::temp<int>' would be invalid: type 'int' cannot be used prior to '::' because it has no members}}
-// expected-note at -2{{because 'typename T::temp<int>' would be invalid: no member named 'temp' in 'D'}}
-// expected-note at -3{{because 'typename T::temp<int>' would be invalid: template name refers to non-type template 'G::template temp'}}
+// expected-note at -1{{because 'typename T::template temp<int>' would be invalid: type 'int' cannot be used prior to '::' because it has no members}}
+// expected-note at -2{{because 'typename T::template temp<int>' would be invalid: no member named 'temp' in 'D'}}
+// expected-note at -3{{because 'typename T::template temp<int>' would be invalid: template name refers to non-type template 'G::template temp'}}
struct r7 {};
using r7i1 = r7<int>; // expected-error{{constraints not satisfied for class template 'r7' [with T = int]}}
Index: clang/lib/AST/TypePrinter.cpp
===================================================================
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1388,7 +1388,7 @@
if (T->getQualifier())
T->getQualifier()->print(OS, Policy);
- OS << T->getIdentifier()->getName();
+ OS << "template " << T->getIdentifier()->getName();
printTemplateArgumentList(OS, T->template_arguments(), Policy);
spaceBeforePlaceHolder(OS);
}
Index: clang/lib/AST/NestedNameSpecifier.cpp
===================================================================
--- clang/lib/AST/NestedNameSpecifier.cpp
+++ clang/lib/AST/NestedNameSpecifier.cpp
@@ -311,6 +311,14 @@
// Print the template argument list.
printTemplateArgumentList(OS, SpecType->template_arguments(),
InnerPolicy);
+ } else if (const auto *DepSpecType =
+ dyn_cast<DependentTemplateSpecializationType>(T)) {
+ // Print the template name without its corresponding
+ // nested-name-specifier.
+ OS << DepSpecType->getIdentifier()->getName();
+ // Print the template argument list.
+ printTemplateArgumentList(OS, DepSpecType->template_arguments(),
+ InnerPolicy);
} else {
// Print the type normally
QualType(T, 0).print(OS, InnerPolicy);
Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-using.cpp
@@ -249,6 +249,17 @@
// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
// CHECK-FIXES: using Nested_t = TwoArgTemplate<TwoArgTemplate<int, Q<T{0 < 0}.b>>, S<(0 < 0), Q<b[0 < 0]>>>;
+template <typename a>
+class TemplateKeyword {
+ typedef typename a::template b<> d;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
+ // CHECK-FIXES: using d = typename a::template b<>;
+
+ typedef typename a::template b<>::c d2;
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
+ // CHECK-FIXES: using d2 = typename a::template b<>::c;
+};
+
template <typename... Args>
class Variadic {};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78139.257774.patch
Type: text/x-patch
Size: 3655 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200415/dce9f0ca/attachment-0001.bin>
More information about the cfe-commits
mailing list