From 4d157af61f9086b7b06925e77abd1d2ce31fd9f7 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Sat, 20 Aug 2016 08:47:52 +0200 Subject: [PATCH] Fixed #7704 (QString::sprintf format string checking) --- cfg/qt.cfg | 10 ++++++++++ test/testio.cpp | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/cfg/qt.cfg b/cfg/qt.cfg index e0291510a..b1af63e99 100644 --- a/cfg/qt.cfg +++ b/cfg/qt.cfg @@ -68,6 +68,16 @@ true + + + false + + + + + + + diff --git a/test/testio.cpp b/test/testio.cpp index 6d24f7d7e..50806066e 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -32,6 +32,7 @@ private: void run() { LOAD_LIB_2(settings.library, "std.cfg"); LOAD_LIB_2(settings.library, "windows.cfg"); + LOAD_LIB_2(settings.library, "qt.cfg"); TEST_CASE(coutCerrMisusage); @@ -57,6 +58,8 @@ private: TEST_CASE(testMicrosoftSecurePrintfArgument); TEST_CASE(testMicrosoftSecureScanfArgument); + TEST_CASE(testQStringFormatArguments); + TEST_CASE(testTernary); // ticket #6182 TEST_CASE(testUnsignedConst); // ticket #6132 @@ -2819,6 +2822,14 @@ private: ASSERT_EQUALS("", errout.str()); } + void testQStringFormatArguments() { + check("void foo(float f) {\n" + " QString string;\n" + " string.sprintf(\"%d\", f);\n" + "}", false, false, Settings::Win32A); + ASSERT_EQUALS("[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'.\n", errout.str()); + } + void testTernary() { // ticket #6182 check("void test(const std::string &val) {\n" " printf(\"%s\n\", val.empty() ? \"I like to eat bananas\" : val.c_str());\n"