From 6e106032276a1f6a723b63e8ba571ab12bd4996c Mon Sep 17 00:00:00 2001 From: Simon Martin Date: Sat, 6 Sep 2014 20:39:04 +0200 Subject: [PATCH] Ticket #6023: Properly handle template'd default template parameter values. --- lib/templatesimplifier.cpp | 7 ++++++- test/testsimplifytokens.cpp | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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 990e5e722..9a78d94a9 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); @@ -2424,6 +2425,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"