[PATCH] D67460: clang-tidy: modernize-use-using work with multi-argument templates

Conrad Poelman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 11 17:17:24 PDT 2019


poelmanc updated this revision to Diff 219834.
poelmanc edited the summary of this revision.

Repository:
  rCTE Clang Tools Extra

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67460/new/

https://reviews.llvm.org/D67460

Files:
  clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
  clang-tools-extra/test/clang-tidy/modernize-use-using.cpp


Index: clang-tools-extra/test/clang-tidy/modernize-use-using.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/modernize-use-using.cpp
+++ clang-tools-extra/test/clang-tidy/modernize-use-using.cpp
@@ -182,4 +182,22 @@
 class E : public C<E> {
   void f() override { super::f(); }
 };
+
+template <typename T1, typename T2>
+class TwoArgTemplate {
+  typedef TwoArgTemplate<T1, T2> self;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef'
+  // CHECK-FIXES: using self = TwoArgTemplate<T1, T2>;
+};
 }
+
+template <bool B, typename T>
+struct S {};
+
+typedef S<(0 > 0 && (3 < 1)), int> S_t, *S_p;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: typedef S<(0 > 0 && (3 < 1)), int> S_t, *S_p;
+
+typedef S<(0 > 0 && (3 < 1)), int> S2_t;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: using S2_t = S<(0 > 0 && (3 < 1)), int>;
Index: clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -40,6 +40,7 @@
 
   Token Tok;
   int ParenLevel = 0;
+  int AngleBracketLevel = 0;
   bool FoundTypedef = false;
 
   while (!DeclLexer.LexFromRawLexer(Tok) && !Tok.is(tok::semi)) {
@@ -54,10 +55,20 @@
     case tok::r_paren:
       ParenLevel--;
       break;
+    case tok::less:
+      // '<' starts a template if not within parentheses like (0 < 1)
+      if (ParenLevel == 0)
+        AngleBracketLevel++;
+      break;
+    case tok::greater:
+      // '>' ends a template if not within parentheses like (0 > 1)
+      if (ParenLevel == 0)
+        AngleBracketLevel--;
+      break;
     case tok::comma:
-      if (ParenLevel == 0) {
-        // If there is comma and we are not between open parenthesis then it is
-        // two or more declarations in this chain.
+      if (ParenLevel == 0 && AngleBracketLevel == 0) {
+        // If there is comma and we are not between open parenthesis or between
+        // open angle brackets then it is two or more declarations in this chain.
         return false;
       }
       break;
@@ -88,8 +99,7 @@
   if (StartLoc.isMacroID() && IgnoreMacros)
     return;
 
-  auto Diag =
-      diag(StartLoc, "use 'using' instead of 'typedef'");
+  auto Diag = diag(StartLoc, "use 'using' instead of 'typedef'");
 
   // do not fix if there is macro or array
   if (MatchedDecl->getUnderlyingType()->isArrayType() || StartLoc.isMacroID())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67460.219834.patch
Type: text/x-patch
Size: 2651 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190912/1ff69f74/attachment.bin>


More information about the cfe-commits mailing list