Fixed #7837 (Field dereference triggers format string type warning)
This commit is contained in:
parent
2e91858640
commit
26fc7abfac
|
@ -1400,7 +1400,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
|
||||||
// TODO: This is a bailout so that old code is used in simple cases. Remove the old code and always use the AST type.
|
// TODO: This is a bailout so that old code is used in simple cases. Remove the old code and always use the AST type.
|
||||||
if (!Token::Match(tok, "%str%|%name% ,|)")) {
|
if (!Token::Match(tok, "%str%|%name% ,|)")) {
|
||||||
const Token *top = tok;
|
const Token *top = tok;
|
||||||
while (top->astParent() && top->astParent()->str() != "," && !(top->astParent()->str() == "(" && top->astParent()->astOperand2()))
|
while (top->astParent() && top->astParent()->str() != "," && top->astParent() != tok->previous())
|
||||||
top = top->astParent();
|
top = top->astParent();
|
||||||
const ValueType *valuetype = top->argumentType();
|
const ValueType *valuetype = top->argumentType();
|
||||||
if (valuetype && valuetype->type >= ValueType::Type::BOOL) {
|
if (valuetype && valuetype->type >= ValueType::Type::BOOL) {
|
||||||
|
|
|
@ -2199,7 +2199,7 @@ private:
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
" printf(\"%f %d\", static_cast<int>(1.0f), reinterpret_cast<const void *>(0));\n"
|
" printf(\"%f %d\", static_cast<int>(1.0f), reinterpret_cast<const void *>(0));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'int'.\n"
|
ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'double' but the argument type is 'signed int'.\n"
|
||||||
"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const void *'.\n", errout.str());
|
"[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const void *'.\n", errout.str());
|
||||||
|
|
||||||
check("void foo() {\n"
|
check("void foo() {\n"
|
||||||
|
@ -2354,6 +2354,16 @@ private:
|
||||||
"[test.cpp:2]: (warning) %hx in format string (no. 6) requires 'unsigned short' but the argument type is 'unsigned int'.\n"
|
"[test.cpp:2]: (warning) %hx in format string (no. 6) requires 'unsigned short' but the argument type is 'unsigned int'.\n"
|
||||||
"[test.cpp:2]: (warning) %hx in format string (no. 7) requires 'unsigned short' but the argument type is 'long'.\n"
|
"[test.cpp:2]: (warning) %hx in format string (no. 7) requires 'unsigned short' but the argument type is 'long'.\n"
|
||||||
"[test.cpp:2]: (warning) %hx in format string (no. 8) requires 'unsigned short' but the argument type is 'unsigned long'.\n", errout.str());
|
"[test.cpp:2]: (warning) %hx in format string (no. 8) requires 'unsigned short' but the argument type is 'unsigned long'.\n", errout.str());
|
||||||
|
|
||||||
|
// #7837 - Use ValueType for function call
|
||||||
|
check("struct S {\n"
|
||||||
|
" double (* f)(double);\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"void foo(struct S x) {\n"
|
||||||
|
" printf(\"%f\", x.f(4.0));\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", 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