diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 9d149c230..6c5ad41d5 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -3494,6 +3494,14 @@ void TemplateSimplifier::simplifyTemplates( const std::time_t maxtime, bool &codeWithTemplates) { + // convert "sizeof ..." to "sizeof..." + for (Token *tok = mTokenList.front(); tok; tok = tok->next()) { + if (Token::simpleMatch(tok, "sizeof ...")) { + tok->str("sizeof..."); + tok->deleteNext(); + } + } + // split ">>" into "> >" fixAngleBrackets(); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index 297b24de7..dca36f880 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -179,6 +179,7 @@ private: TEST_CASE(template139); TEST_CASE(template140); TEST_CASE(template141); // #9337 + TEST_CASE(template142); // #9338 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) @@ -3274,7 +3275,7 @@ private: "template < class , template < class > class , class > struct e ; " "template < class f , class g , class ... h > " "using i = typename e < f , g :: template fn , h ... > :: d ; " - "template < class ... j > struct k : c < sizeof ... ( j ) , int > :: template fn < j ... > { } ;"; + "template < class ... j > struct k : c < sizeof... ( j ) , int > :: template fn < j ... > { } ;"; ASSERT_EQUALS(exp, tok(code)); } @@ -3441,6 +3442,20 @@ private: ASSERT_EQUALS(exp, tok(code)); } + void template142() { // #9338 + const char code[] = "template struct a;\n" + "template struct a {\n" + " using typename b ::e;\n" + " static_assert(e::f ? sizeof...(d) : sizeof...(d), \"\");\n" + "};"; + const char exp[] = "template < typename ... > struct a ; " + "template < typename b , typename c , typename ... d > struct a < b c :: * , d ... > { " + "using b :: e ; " + "static_assert ( e :: f ? sizeof... ( d ) : sizeof... ( d ) , \"\" ) ; " + "} ;"; + 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"