diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 516add4c8..c20b4e981 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1221,7 +1221,7 @@ void TemplateSimplifier::simplifyTemplateAliases() break; } } - if (!tok2 || tok2->str() != ">" || args.size() != aliasParameters.size()) { + if (!tok2 || tok2->str() != ">" || (!aliasDeclaration.isVariadic() && (args.size() != aliasParameters.size()))) { ++it2; continue; } @@ -1597,6 +1597,10 @@ void TemplateSimplifier::expandTemplate( ++typeindentlevel; else if (typeindentlevel > 0 && typetok->str() == ">") --typeindentlevel; + else if (typetok->str() == "(") + ++typeindentlevel; + else if (typetok->str() == ")") + --typeindentlevel; dst->insertToken(typetok->str(), typetok->originalName(), true); Token *previous = dst->previous(); previous->isTemplateArg(true); @@ -1818,6 +1822,10 @@ void TemplateSimplifier::expandTemplate( ++typeindentlevel; else if (typeindentlevel > 0 && typetok->str() == ">") --typeindentlevel; + else if (typetok->str() == "(") + ++typeindentlevel; + else if (typetok->str() == ")") + --typeindentlevel; mTokenList.addtoken(typetok, tok5->linenr(), tok5->fileIndex()); Token *back = mTokenList.back(); if (Token::Match(back, "{|(|[")) { @@ -1918,6 +1926,10 @@ void TemplateSimplifier::expandTemplate( ++typeindentlevel; else if (typeindentlevel > 0 && typetok->str() == ">") --typeindentlevel; + else if (typetok->str() == "(") + ++typeindentlevel; + else if (typetok->str() == ")") + --typeindentlevel; if (copy) { mTokenList.addtoken(typetok, tok3->linenr(), tok3->fileIndex()); Token *back = mTokenList.back(); @@ -2992,6 +3004,10 @@ void TemplateSimplifier::replaceTemplateUsage( while (tok2 != endToken && (indentlevel2 > 0 || tok2->str() != ">")) { if (tok2->str() == "<" && (tok2->strAt(1) == ">" || templateParameters(tok2))) ++indentlevel2; + else if (tok2->str() == "(") + ++indentlevel2; + else if (tok2->str() == ")") + --indentlevel2; else if (indentlevel2 > 0 && Token::Match(tok2, "> [,>]")) --indentlevel2; else if (indentlevel2 == 0) { diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index d6892bd35..a5c4bbde3 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -167,6 +167,7 @@ private: TEST_CASE(template127); // #9225 TEST_CASE(template128); // #9224 TEST_CASE(template129); + TEST_CASE(template130); // #9246 TEST_CASE(template_specialization_1); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_specialization_2); // #7868 - template specialization template struct S> {..}; TEST_CASE(template_enum); // #6299 Syntax error in complex enum declaration (including template) @@ -3087,6 +3088,19 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template130() { // #9246 + const char code[] = "template using a = int;\n" + "template using b = a<>;\n" + "template void c();\n" + "template void e() { c, int>; }\n" + "void f() { e(); }"; + const char exp[] = "template < typename , typename > void c ( ) ; " + "void e ( ) ; " + "void f ( ) { e ( ) ; } " + "void e ( ) { c < int , int > ; }"; + ASSERT_EQUALS(exp, tok(code)); + } + void template_specialization_1() { // #7868 - template specialization template struct S> {..}; const char code[] = "template struct C {};\n" "template struct S {a};\n"