Fix sizeof sizeof check to handle sizeof(sizeof type)
This commit is contained in:
parent
9a383388be
commit
d592250284
|
@ -2834,8 +2834,11 @@ void CheckOther::sizeofsizeof()
|
||||||
return;
|
return;
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
if (Token::simpleMatch(tok, "sizeof sizeof"))
|
if (Token::Match(tok, "sizeof (| sizeof"))
|
||||||
|
{
|
||||||
sizeofsizeofError(tok);
|
sizeofsizeofError(tok);
|
||||||
|
tok = tok->next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -961,6 +961,18 @@ private:
|
||||||
" int i = sizeof sizeof char;\n"
|
" int i = sizeof sizeof char;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Calling sizeof for 'sizeof'.\n", errout.str());
|
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()
|
void sizeofCalculation()
|
||||||
|
|
Loading…
Reference in New Issue