diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 5f56695b8..8b77f876a 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -600,11 +600,16 @@ void TemplateSimplifier::useDefaultArgumentValues(const std::list &temp for (std::size_t i = (templatepar - eq.size()); it != eq.end() && i < usedpar; ++i) ++it; while (it != eq.end()) { + int indentlevel = 0; tok->insertToken(","); tok = tok->next(); const Token *from = (*it)->next(); std::stack links; - while (from && (!links.empty() || (from->str() != "," && from->str() != ">"))) { + while (from && (!links.empty() || (from->str() != "," && (indentlevel || from->str() != ">")))) { + if (from->str() == "<") + ++indentlevel; + else if (from->str() == ">") + --indentlevel; tok->insertToken(from->str(), from->originalName()); tok = tok->next(); if (Token::Match(tok, "(|[")) diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 27a8d1e0f..b55eae209 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -139,6 +139,7 @@ private: TEST_CASE(template44); // #5297 - TemplateSimplifier::simplifyCalculations not eager enough TEST_CASE(template45); // #5814 - syntax error reported for valid code TEST_CASE(template46); // #5816 - syntax error reported for valid code + TEST_CASE(template47); // #6023 - syntax error reported for valid code TEST_CASE(template_unhandled); TEST_CASE(template_default_parameter); TEST_CASE(template_default_type); @@ -2425,6 +2426,12 @@ private: ASSERT_EQUALS("", errout.str()); } + void template47() { // #6023 + tok("template > class C1 {}; " + "class C2 : public C1 {};"); + ASSERT_EQUALS("", errout.str()); + } + void template_default_parameter() { { const char code[] = "template \n"