diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 267ac15dd..4add01fc9 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2059,6 +2059,8 @@ void TemplateSimplifier::expandTemplate( Token * const beforeTypeToken = mTokenList.back(); bool pointerType = false; const bool isVariadicTemplateArg = templateDeclaration.isVariadic() && itype + 1 == typeParametersInDeclaration.size(); + if (isVariadicTemplateArg && mTypesUsedInTemplateInstantiation.size() > 1 && !Token::simpleMatch(tok3->next(), "...")) + continue; if (isVariadicTemplateArg && Token::Match(tok3, "%name% ... %name%")) tok3 = tok3->tokAt(2); const std::string endStr(isVariadicTemplateArg ? ">" : ",>"); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index fdc3600c8..236ec20de 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -279,6 +279,7 @@ private: TEST_CASE(template_variadic_1); // #9144 TEST_CASE(template_variadic_2); // #4349 TEST_CASE(template_variadic_3); // #6172 + TEST_CASE(template_variadic_4); TEST_CASE(template_variable_1); TEST_CASE(template_variable_2); @@ -6133,6 +6134,25 @@ private: ASSERT_EQUALS(expected, tok(code)); } + void template_variadic_4() { // #11763 + const char code[] = "template \n" + "class E {\n" + " template \n" + " int f(int n, std::integer_sequence) {\n" + " return (((I == n) ? N : 0) + ...);\n" + " }\n" + "};\n" + "E<1, 3> e;\n"; + const char expected[] = "class E<1,3> ; E<1,3> e ; " + "class E<1,3> { " + "template < int ... I > " + "int f ( int n , std :: integer_sequence < int , I ... > ) { " + "return ( ( ( I == n ) ? : 0 ) + ... ) ; " + "} " + "} ;"; + ASSERT_EQUALS(expected, tok(code)); + } + void template_variable_1() { { const char code[] = "template const int foo = N*N;\n"