Fix sizeof sizeof check to handle sizeof(sizeof type)

This commit is contained in:
Raphael Geissert 2011-02-02 10:56:02 -06:00
parent 9a383388be
commit d592250284
2 changed files with 16 additions and 1 deletions

View File

@ -2834,8 +2834,11 @@ void CheckOther::sizeofsizeof()
return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (Token::simpleMatch(tok, "sizeof sizeof"))
if (Token::Match(tok, "sizeof (| sizeof"))
{
sizeofsizeofError(tok);
tok = tok->next();
}
}
}

View File

@ -961,6 +961,18 @@ private:
" int i = sizeof sizeof char;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Calling sizeof for 'sizeof'.\n", errout.str());
check("void foo()\n"
"{\n"
" int i = sizeof (sizeof long);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Calling sizeof for 'sizeof'.\n", errout.str());
check("void foo(long *p)\n"
"{\n"
" int i = sizeof (sizeof (p));\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (warning) Calling sizeof for 'sizeof'.\n", errout.str());
}
void sizeofCalculation()