Fixed #1050 (Internal error: In tokenizer for: 'do { sizeof 1; } while (0);')

This commit is contained in:
Daniel Marjamäki 2009-12-06 08:46:59 +01:00
parent e66156ab5c
commit 75f6e20e61
2 changed files with 23 additions and 1 deletions

View File

@ -1745,8 +1745,17 @@ void Tokenizer::simplifySizeof()
Token::createMutualLinks(tok->next(), tok->tokAt(4));
}
// sizeof 1 => sizeof ( 1 )
if (tok->next()->isNumber())
{
Token *tok2 = tok->next();
tok->insertToken("(");
tok2->insertToken(")");
Token::createMutualLinks(tok->next(), tok2->next());
}
// sizeof int -> sizeof( int )
if (tok->next()->str() != "(")
else if (tok->next()->str() != "(")
{
// Add parenthesis around the sizeof
for (Token *tempToken = tok->next(); tempToken; tempToken = tempToken->next())

View File

@ -72,6 +72,7 @@ private:
TEST_CASE(sizeof14);
TEST_CASE(sizeof15);
TEST_CASE(sizeof16);
TEST_CASE(sizeof17);
TEST_CASE(casting);
TEST_CASE(strlen1);
@ -938,6 +939,18 @@ private:
ASSERT_EQUALS("", errout.str());
}
void sizeof17()
{
// ticket #1050
const char code[] = "void f()\n"
"{\n"
" sizeof 1;\n"
" while (0);\n"
"}\n";
ASSERT_EQUALS("void f ( ) { sizeof ( 1 ) ; while ( false ) { ; } }", tok(code));
ASSERT_EQUALS("", errout.str());
}
void casting()
{
{