Fixed #1046 (tokenizer: internal error for 'discard_block< (1 << 24), 10, 24 > u, v;')

This commit is contained in:
Daniel Marjamäki 2009-12-05 21:15:14 +01:00
parent 42093911d6
commit e9b342c56b
2 changed files with 22 additions and 1 deletions

View File

@ -3052,7 +3052,7 @@ void Tokenizer::simplifyVarDecl()
// //
if (Token::simpleMatch(tok2, "std ::")) if (Token::simpleMatch(tok2, "std ::"))
{ {
typelen += 1; typelen += 2;
tok2 = tok2->tokAt(2); tok2 = tok2->tokAt(2);
} }
@ -3097,6 +3097,7 @@ void Tokenizer::simplifyVarDecl()
if (Token::Match(tok2, "%var% ,")) if (Token::Match(tok2, "%var% ,"))
{ {
tok2 = tok2->next(); // The ',' token tok2 = tok2->next(); // The ',' token
typelen--;
} }
else else
{ {
@ -3117,6 +3118,17 @@ void Tokenizer::simplifyVarDecl()
{ {
tok2->str(";"); tok2->str(";");
insertTokens(tok2, type0, typelen); insertTokens(tok2, type0, typelen);
std::list<Token *> link;
while (((typelen--) > 0) && (0 != (tok2 = tok2->next())))
{
if (tok2->str() == "(")
link.push_back(tok2);
else if (tok2->str() == ")" && !link.empty())
{
Token::createMutualLinks(tok2, link.back());
link.pop_back();
}
}
} }
else else

View File

@ -153,6 +153,7 @@ private:
TEST_CASE(vardecl9); TEST_CASE(vardecl9);
TEST_CASE(vardecl10); TEST_CASE(vardecl10);
TEST_CASE(vardecl_stl); TEST_CASE(vardecl_stl);
TEST_CASE(vardecl_template);
TEST_CASE(volatile_variables); TEST_CASE(volatile_variables);
TEST_CASE(syntax_error); TEST_CASE(syntax_error);
@ -2349,6 +2350,14 @@ private:
ASSERT_EQUALS(res3, tokenizeAndStringify(code3)); ASSERT_EQUALS(res3, tokenizeAndStringify(code3));
} }
void vardecl_template()
{
// ticket #1046
const char code1[] = "b<(1<<24),10,24> u, v;";
const char res1[] = "b < ( 1 << 24 ) , 10 , 24 > u ; b < ( 1 << 24 ) , 10 , 24 > v ;";
ASSERT_EQUALS(res1, tokenizeAndStringify(code1));
}
void vardec_static() void vardec_static()
{ {
{ {