diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index d67356ad086..4cff68fc509 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3201,8 +3201,15 @@ bool Tokenizer::simplifyUsing() continue; } - // skip template definitions if (Token::Match(tok1, "template < !!>")) { + Token *paramsEnd = tok1->next()->findClosingBracket(); + bool shadowed = !paramsEnd; + for (const Token *param = tok1->next(); !shadowed && param != paramsEnd; param = param->next()) + shadowed = param->str() == nameToken->str(); + if (!shadowed) { + tok1 = paramsEnd; + continue; + } Token *declEndToken = TemplateSimplifier::findTemplateDeclarationEnd(tok1); if (declEndToken) tok1 = declEndToken; diff --git a/test/testsimplifyusing.cpp b/test/testsimplifyusing.cpp index e3c714803cb..239407f5c2f 100644 --- a/test/testsimplifyusing.cpp +++ b/test/testsimplifyusing.cpp @@ -79,6 +79,7 @@ class TestSimplifyUsing : public TestFixture { TEST_CASE(simplifyUsing39); TEST_CASE(simplifyUsing40); TEST_CASE(simplifyUsing41); + TEST_CASE(simplifyUsing42); TEST_CASE(simplifyUsing8970); TEST_CASE(simplifyUsing8971); @@ -956,6 +957,40 @@ class TestSimplifyUsing : public TestFixture { ASSERT_EQUALS(expected, tok(code)); } + void simplifyUsing42() { + { + const char code[] = "using A = bool;\n" + "template A func() {}\n"; + const char expected[] = "template < typename T > bool func ( ) { }"; + ASSERT_EQUALS(expected, tok(code)); + } + { + const char code[] = "using A = bool;\n" + "template A func() {}\n"; + const char expected[] = "template < typename A > A func ( ) { }"; + ASSERT_EQUALS(expected, tok(code)); + } + { + const char code[] = "using A = bool;\n" + "template class C { A x; }\n"; + const char expected[] = "template < typename T > class C { bool x ; }"; + ASSERT_EQUALS(expected, tok(code)); + } + { + const char code[] = "using A = bool;\n" + "template class C { A x; }\n"; + const char expected[] = "template < typename A > class C { A x ; }"; + ASSERT_EQUALS(expected, tok(code)); + } + { + const char code[] = "using A = bool;\n" + "template class C { using A = T; A x; }\n" + "C c;\n"; + const char expected[] = "class C ; C c ; class C { int x ; }"; + ASSERT_EQUALS(expected, tok(code)); + } + } + void simplifyUsing8970() { const char code[] = "using V = std::vector;\n" "struct A {\n"