Fixed #954 (Tokenizer: correctly simplify sizeof of class members)

http://sourceforge.net/apps/trac/cppcheck/ticket/954
This commit is contained in:
Slava Semushin 2009-11-14 01:07:44 +06:00
parent 6384b83938
commit 2ec5438186
2 changed files with 22 additions and 0 deletions

View File

@ -1721,6 +1721,11 @@ void Tokenizer::simplifySizeof()
// nothing after this
tempToken = tempToken->tokAt(2);
}
else if (Token::simpleMatch(tempToken->next(), ") ."))
{
tempToken = tempToken->tokAt(2);
continue;
}
// Ok, we should be clean. Add ) after tempToken
tok->insertToken("(");

View File

@ -69,6 +69,7 @@ private:
TEST_CASE(sizeof11);
TEST_CASE(sizeof12);
TEST_CASE(sizeof13);
TEST_CASE(sizeof14);
TEST_CASE(casting);
TEST_CASE(strlen1);
@ -884,6 +885,22 @@ private:
ASSERT_EQUALS(expected, tok(code));
}
void sizeof14()
{
// ticket #954
const char code[] = "void f()\n"
"{\n"
" A **a;\n"
" int aa = sizeof *(*a)->b;\n"
"}\n";
const char expected[] = "void f ( ) "
"{"
" A * * a ;"
" int aa ; aa = sizeof ( * ( * a ) . b ) ; "
"}";
ASSERT_EQUALS(expected, tok(code));
}
void casting()
{
{