Ticket #6134: Improve the mechanism differentiating template declarations from template definitions.

This commit is contained in:
Simon Martin 2014-09-13 16:44:05 +02:00
parent 1e298a31cf
commit 01cf008792
2 changed files with 16 additions and 1 deletions

View File

@ -472,11 +472,19 @@ std::list<Token *> 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);

View File

@ -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> int f( { } ); "
"int foo = f<1>(0);");
ASSERT_EQUALS("", errout.str());
}
void template_default_parameter() {
{
const char code[] = "template <class T, int n=3>\n"