diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 8b77f876a..62789d223 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -472,11 +472,19 @@ std::list TemplateSimplifier::getTemplateDeclarations(Token *tokens, bo Token *parmEnd = tok->next()->findClosingBracket(); codeWithTemplates = true; + int indentlevel = 0; for (const Token *tok2 = parmEnd; tok2; tok2 = tok2->next()) { + if (tok2->str() == "(") + ++indentlevel; + else if (tok2->str() == ")") + --indentlevel; + + if (indentlevel) // In an argument list; move to the next token + continue; + // Just a declaration => ignore this if (tok2->str() == ";") break; - // Implementation => add to "templates" if (tok2->str() == "{") { templates.push_back(tok); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index b55eae209..b3802b8da 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -140,6 +140,7 @@ private: 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(template48); // #6134 - 100% CPU upon invalid code TEST_CASE(template_unhandled); TEST_CASE(template_default_parameter); TEST_CASE(template_default_type); @@ -2432,6 +2433,12 @@ private: ASSERT_EQUALS("", errout.str()); } + void template48() { // #6134 + tok("template int f( { } ); " + "int foo = f<1>(0);"); + ASSERT_EQUALS("", errout.str()); + } + void template_default_parameter() { { const char code[] = "template \n"