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()) 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 { void f() override { super::f(); } }; + +template +class TwoArgTemplate { + typedef TwoArgTemplate self; + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use 'using' instead of 'typedef' + // CHECK-FIXES: using self = TwoArgTemplate; +}; } + +template +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>;