diff --git a/lib/checkio.cpp b/lib/checkio.cpp index d919c1bcd..15ba800ea 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -1218,7 +1218,17 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings) if (tok->type() == Token::eString) { typeToken = tok; 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() == "&") { address = true; tok = tok->next(); diff --git a/test/testio.cpp b/test/testio.cpp index c15342875..11710bf3b 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -2036,6 +2036,13 @@ private: " printf(\"%c\", c);\n" "}\n", false, false, Settings::Win64); ASSERT_EQUALS("", errout.str()); + + check("void foo() {\n" + " printf(\"%f %d\", static_cast(1.0f), reinterpret_cast(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