CheckIO: Handling of casts (#4964)
This commit is contained in:
parent
17810e4eb5
commit
5aba841499
|
@ -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();
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue