From 9d45d1a33819e4655ed572ddf247d520baa7f78e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 12 Feb 2026 13:26:03 +0100 Subject: [PATCH 1/4] Update templatesimplifier.cpp --- lib/templatesimplifier.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 023fe5618ad..09b1b3e1b98 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2104,8 +2104,6 @@ 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::Match(tok3->next(), "...|<")) - continue; if (isVariadicTemplateArg && Token::Match(tok3, "%name% ... %name%")) tok3 = tok3->tokAt(2); if (!isVariadicTemplateArg && copy && Token::Match(mTypesUsedInTemplateInstantiation[itype].token(), "%num% ,|>|>>") && @@ -2130,6 +2128,7 @@ void TemplateSimplifier::expandTemplate( } } const std::string endStr(isVariadicTemplateArg ? ">" : ",>"); + Token* begPar = nullptr; for (Token *typetok = mTypesUsedInTemplateInstantiation[itype].token(); typetok && (typeindentlevel > 0 || endStr.find(typetok->str()[0]) == std::string::npos); typetok = typetok->next()) { @@ -2153,6 +2152,10 @@ void TemplateSimplifier::expandTemplate( --typeindentlevel; Token *back; if (copy) { + if (isVariadicTemplateArg && typetok == mTypesUsedInTemplateInstantiation[itype].token() && typetok->isLiteral()) { + mTokenList.addtoken("(", mTokenList.back()); + begPar = mTokenList.back(); + } mTokenList.addtoken(typetok, tok3); back = mTokenList.back(); } else @@ -2181,6 +2184,10 @@ void TemplateSimplifier::expandTemplate( if (copy) back->templateArgFrom(typetok); } + if (begPar) { + mTokenList.addtoken(")", mTokenList.back()); + Token::createMutualLinks(begPar, mTokenList.back()); + } if (pointerType && Token::simpleMatch(beforeTypeToken, "const")) { mTokenList.addtoken(beforeTypeToken); beforeTypeToken->deleteThis(); From b38abd4891bc1384f7bbd18c28cf2be2c8e54910 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 12 Feb 2026 13:27:12 +0100 Subject: [PATCH 2/4] Update testsimplifytemplate.cpp --- test/testsimplifytemplate.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 52df0597f92..4e2ea686714 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -6390,6 +6390,18 @@ class TestSimplifyTemplate : public TestFixture { "A a ; " "struct A { } ;"; ASSERT_EQUALS(expected2, tok(code2)); + + const char code3[] = "template \n" // #14477 + " int f() {\n" + " return (0 | ... | (1, 2, 4));\n" + "}\n" + "int main() {\n" + " return f<1, 2, 4>();\n" + "}\n"; + const char expected3[] = "int f<1,2,4> ( ) ; " + "int main ( ) { return f<1,2,4> ( ) ; } " + "int f<1,2,4> ( ) { return ( 0 | ... | ( 1 , 2 , 4 ) ) ; }"; + ASSERT_EQUALS(expected3, tok(code3)); } void template_variable_1() { From 1497cde2c1f0501d568dd70010f8dd1e81f36820 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 12 Feb 2026 13:28:45 +0100 Subject: [PATCH 3/4] Update testsimplifytemplate.cpp --- test/testsimplifytemplate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 4e2ea686714..b0af26465c1 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -6372,7 +6372,7 @@ class TestSimplifyTemplate : public TestFixture { "class E<1,3> { " "template < int ... I > " "int f ( int n , std :: integer_sequence < int , I ... > ) { " - "return ( ( ( I == n ) ? : 0 ) + ... ) ; " + "return ( ( ( I == n ) ? ( 1 , 3 ) : 0 ) + ... ) ; " "} " "} ;"; ASSERT_EQUALS(expected, tok(code)); From c1476884c9d3705702e1b9363669ab303dbfd1c9 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 12 Feb 2026 13:34:20 +0100 Subject: [PATCH 4/4] Update templatesimplifier.cpp --- lib/templatesimplifier.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 09b1b3e1b98..d4f34cbec23 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -2153,8 +2153,8 @@ void TemplateSimplifier::expandTemplate( Token *back; if (copy) { if (isVariadicTemplateArg && typetok == mTypesUsedInTemplateInstantiation[itype].token() && typetok->isLiteral()) { - mTokenList.addtoken("(", mTokenList.back()); - begPar = mTokenList.back(); + mTokenList.addtoken("(", mTokenList.back()); + begPar = mTokenList.back(); } mTokenList.addtoken(typetok, tok3); back = mTokenList.back();