sizeof for numeric constant : disabled check. see ticket #3179

This commit is contained in:
Daniel Marjamäki 2011-11-27 18:50:21 +01:00
parent c0770f0823
commit 522da8d258
2 changed files with 13 additions and 4 deletions

View File

@ -333,6 +333,11 @@ void CheckOther::fflushOnInputStreamError(const Token *tok, const std::string &v
//---------------------------------------------------------------------------
void CheckOther::checkSizeofForNumericParameter()
{
// TODO: write sensible error message if char constant is used
// see ticket #3179
if (!_settings->experimental)
return;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "sizeof ( %num% )")
|| Token::Match(tok, "sizeof %num%")

View File

@ -3070,25 +3070,29 @@ private:
void sizeofForNumericParameter() {
check("void f() {\n"
" std::cout << sizeof(10) << std::endl;\n"
"}\n"
"}\n",
NULL, true
);
ASSERT_EQUALS("[test.cpp:2]: (error) Using sizeof with a numeric constant as function argument might not be what you intended.\n", errout.str());
check("void f() {\n"
" std::cout << sizeof(-10) << std::endl;\n"
"}\n"
"}\n",
NULL, true
);
ASSERT_EQUALS("[test.cpp:2]: (error) Using sizeof with a numeric constant as function argument might not be what you intended.\n", errout.str());
check("void f() {\n"
" std::cout << sizeof 10 << std::endl;\n"
"}\n"
"}\n",
NULL, true
);
ASSERT_EQUALS("[test.cpp:2]: (error) Using sizeof with a numeric constant as function argument might not be what you intended.\n", errout.str());
check("void f() {\n"
" std::cout << sizeof -10 << std::endl;\n"
"}\n"
"}\n",
NULL, true
);
ASSERT_EQUALS("[test.cpp:2]: (error) Using sizeof with a numeric constant as function argument might not be what you intended.\n", errout.str());