Merge pull request #432 from simartin/ticket_6134

Ticket #6134: Improve the mechanism differentiating template declarations from template definitions.
This commit is contained in:
PKEuS 2014-09-13 18:26:21 +02:00
commit 01c2d4e683
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(); Token *parmEnd = tok->next()->findClosingBracket();
codeWithTemplates = true; codeWithTemplates = true;
int indentlevel = 0;
for (const Token *tok2 = parmEnd; tok2; tok2 = tok2->next()) { 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 // Just a declaration => ignore this
if (tok2->str() == ";") if (tok2->str() == ";")
break; break;
// Implementation => add to "templates" // Implementation => add to "templates"
if (tok2->str() == "{") { if (tok2->str() == "{") {
templates.push_back(tok); templates.push_back(tok);

View File

@ -140,6 +140,7 @@ private:
TEST_CASE(template45); // #5814 - syntax error reported for valid code TEST_CASE(template45); // #5814 - syntax error reported for valid code
TEST_CASE(template46); // #5816 - 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(template47); // #6023 - syntax error reported for valid code
TEST_CASE(template48); // #6134 - 100% CPU upon invalid code
TEST_CASE(template_unhandled); TEST_CASE(template_unhandled);
TEST_CASE(template_default_parameter); TEST_CASE(template_default_parameter);
TEST_CASE(template_default_type); TEST_CASE(template_default_type);
@ -2432,6 +2433,12 @@ private:
ASSERT_EQUALS("", errout.str()); 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() { void template_default_parameter() {
{ {
const char code[] = "template <class T, int n=3>\n" const char code[] = "template <class T, int n=3>\n"