Tokenizer: better handling of 'struct AB ab; sizeof(ab)'

This commit is contained in:
Daniel Marjamäki 2011-07-16 22:07:30 +02:00
parent cf3ab649fb
commit 35938e74ad
2 changed files with 14 additions and 0 deletions

View File

@ -4191,6 +4191,11 @@ void Tokenizer::simplifySizeof()
sizeOfVar[varId] = MathLib::toString<unsigned int>(size); sizeOfVar[varId] = MathLib::toString<unsigned int>(size);
} }
else if (Token::Match(tok->tokAt(-3), "[;{}(,] struct %type% %var% [;,)]"))
{
sizeOfVar[varId] = "100";
}
else if (Token::Match(tok->tokAt(-1), "%type% %var% [ %num% ] [;=]") || else if (Token::Match(tok->tokAt(-1), "%type% %var% [ %num% ] [;=]") ||
Token::Match(tok->tokAt(-2), "%type% * %var% [ %num% ] [;=]")) Token::Match(tok->tokAt(-2), "%type% * %var% [ %num% ] [;=]"))
{ {

View File

@ -86,6 +86,7 @@ private:
TEST_CASE(sizeof21); // #2232 - sizeof...(Args) TEST_CASE(sizeof21); // #2232 - sizeof...(Args)
TEST_CASE(sizeof22); // #2599 TEST_CASE(sizeof22); // #2599
TEST_CASE(sizeof23); // #2604 TEST_CASE(sizeof23); // #2604
TEST_CASE(sizeof24); // struct variable
TEST_CASE(sizeofsizeof); TEST_CASE(sizeofsizeof);
TEST_CASE(casting); TEST_CASE(casting);
@ -1475,6 +1476,14 @@ private:
tok(code); tok(code);
} }
void sizeof24()
{
const char code[] = "; struct AB ab; sizeof(ab)";
// don't segfault
ASSERT_EQUALS("; struct AB ab ; 100", tok(code));
}
void sizeofsizeof() void sizeofsizeof()
{ {