From 26fc7abfac0a69dba01c0923a852214f87cc5c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 25 Feb 2017 18:22:14 +0100 Subject: [PATCH] Fixed #7837 (Field dereference triggers format string type warning) --- lib/checkio.cpp | 2 +- test/testio.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index ab9f97b27..a1cc7c682 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -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. if (!Token::Match(tok, "%str%|%name% ,|)")) { 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(); const ValueType *valuetype = top->argumentType(); if (valuetype && valuetype->type >= ValueType::Type::BOOL) { diff --git a/test/testio.cpp b/test/testio.cpp index b2367bac8..5ae6b568e 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -2199,7 +2199,7 @@ private: 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" + 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()); 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. 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()); + + // #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