CheckIO: Handling of casts (#4964)

This commit is contained in:
Robert Reif 2013-10-02 04:12:46 +02:00 committed by Daniel Marjamäki
parent 17810e4eb5
commit 5aba841499
2 changed files with 18 additions and 1 deletions

View File

@ -1218,7 +1218,17 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings)
if (tok->type() == Token::eString) { if (tok->type() == Token::eString) {
typeToken = tok; typeToken = tok;
return; return;
} else if (tok->str() == "&" || tok->type() == Token::eVariable || tok->type() == Token::eFunction || Token::Match(tok, "%type% ::")) { } else if (tok->str() == "&" || tok->type() == Token::eVariable ||
tok->type() == Token::eFunction || Token::Match(tok, "%type% ::") ||
(Token::Match(tok, "static_cast|reinterpret_cast|const_cast <") &&
Token::Match(tok->linkAt(1), "> (") &&
Token::Match(tok->linkAt(1)->linkAt(1), ") ,|)"))) {
if (Token::Match(tok, "static_cast|reinterpret_cast|const_cast")) {
typeToken = tok->tokAt(2);
if (typeToken->str() == "const")
typeToken = typeToken->next();
return;
}
if (tok->str() == "&") { if (tok->str() == "&") {
address = true; address = true;
tok = tok->next(); tok = tok->next();

View File

@ -2036,6 +2036,13 @@ private:
" printf(\"%c\", c);\n" " printf(\"%c\", c);\n"
"}\n", false, false, Settings::Win64); "}\n", false, false, Settings::Win64);
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" printf(\"%f %d\", static_cast<int>(1.0f), reinterpret_cast<const void *>(0));\n"
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'int'.\n"
"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const void *'.\n", errout.str());
} }
void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings void testPosixPrintfScanfParameterPosition() { // #4900 - No support for parameters in format strings