From d7b3eccfd328faab09dd8f0eb7fd960ede279c18 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 26 Feb 2024 04:00:45 +0100 Subject: [PATCH] TestIO: cleaned up by using an object to pass the options --- Makefile | 2 +- test/testio.cpp | 333 ++++++++++++++++++++++++------------------------ 2 files changed, 169 insertions(+), 166 deletions(-) diff --git a/Makefile b/Makefile index f99bc4e50ff..efe125d3d5b 100644 --- a/Makefile +++ b/Makefile @@ -766,7 +766,7 @@ test/testincompletestatement.o: test/testincompletestatement.cpp lib/addoninfo.h test/testinternal.o: test/testinternal.cpp lib/addoninfo.h lib/check.h lib/checkinternal.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testinternal.cpp -test/testio.o: test/testio.cpp lib/addoninfo.h lib/check.h lib/checkio.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h +test/testio.o: test/testio.cpp lib/addoninfo.h lib/check.h lib/checkio.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testio.cpp test/testleakautovar.o: test/testleakautovar.cpp lib/addoninfo.h lib/check.h lib/checkleakautovar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h diff --git a/test/testio.cpp b/test/testio.cpp index c20e162eb83..7d79eec0ee6 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -20,6 +20,7 @@ #include "checkio.h" #include "config.h" #include "errortypes.h" +#include "helpers.h" #include "platform.h" #include "settings.h" #include "fixture.h" @@ -28,14 +29,13 @@ #include // IWYU pragma: keep #include - class TestIO : public TestFixture { public: TestIO() : TestFixture("TestIO") {} private: const Settings settings = settingsBuilder().library("std.cfg").library("windows.cfg").library("qt.cfg").build(); - /*const*/ Settings settings1 = settingsBuilder().library("std.cfg").library("windows.cfg").library("qt.cfg").build(); + /*const*/ Settings settings1 = settingsBuilder().library("std.cfg").library("windows.cfg").library("qt.cfg").severity(Severity::warning).severity(Severity::style).build(); void run() override { TEST_CASE(coutCerrMisusage); @@ -81,28 +81,34 @@ class TestIO : public TestFixture { TEST_CASE(testParameterPack); // #11289 } + struct CheckOptions + { + CheckOptions() = default; + bool inconclusive = false; + bool portability = false; + Platform::Type platform = Platform::Type::Unspecified; + bool onlyFormatStr = false; + bool cpp = true; + }; + #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) - void check_(const char* file, int line, const char* code, bool inconclusive = false, bool portability = false, Platform::Type platform = Platform::Type::Unspecified, bool onlyFormatStr = false, bool cpp = true) { + void check_(const char* file, int line, const char* code, const CheckOptions& options = make_default_obj()) { // Clear the error buffer.. errout.str(""); // TODO: using dedicated Settings (i.e. copying it) object causes major slowdown - settings1.severity.clear(); - settings1.severity.enable(Severity::warning); - settings1.severity.enable(Severity::style); - if (portability) - settings1.severity.enable(Severity::portability); - settings1.certainty.setEnabled(Certainty::inconclusive, inconclusive); - PLATFORM(settings1.platform, platform); + settings1.severity.setEnabled(Severity::portability, options.portability); + settings1.certainty.setEnabled(Certainty::inconclusive, options.inconclusive); + PLATFORM(settings1.platform, options.platform); // Tokenize.. Tokenizer tokenizer(settings1, this); std::istringstream istr(code); - const std::string file_in = cpp ? "test.cpp" : "test.c"; + const std::string file_in = options.cpp ? "test.cpp" : "test.c"; ASSERT_LOC(tokenizer.tokenize(istr, file_in.c_str()), file, line); // Check.. - if (onlyFormatStr) { + if (options.onlyFormatStr) { CheckIO checkIO(&tokenizer, &settings1, this); checkIO.checkWrongPrintfScanfArguments(); return; @@ -178,7 +184,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); check("void foo(FILE*& f) {\n" @@ -186,7 +192,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); check("void foo(FILE*& f) {\n" @@ -194,7 +200,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); check("void foo(FILE*& f) {\n" @@ -202,7 +208,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); check("void foo(FILE*& f) {\n" @@ -210,7 +216,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); check("void foo(FILE*& f) {\n" @@ -218,7 +224,7 @@ class TestIO : public TestFixture { " fread(buffer, 5, 6, f);\n" " rewind(f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); check("void foo(FILE*& f) {\n" @@ -230,43 +236,43 @@ class TestIO : public TestFixture { check("void foo(FILE*& f) {\n" " f = _wfopen(name, L\"r+\");\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout.str()); check("void foo(FILE*& f) {\n" " f = _tfopen(name, _T(\"r+\"));\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("", errout.str()); check("void foo(FILE*& f) {\n" " f = _tfopen(name, _T(\"r+\"));\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout.str()); check("void foo(FILE*& f) {\n" " _wfopen_s(&f, name, L\"r+\");\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout.str()); check("void foo(FILE*& f) {\n" " _tfopen_s(&f, name, _T(\"r+\"));\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("", errout.str()); check("void foo(FILE*& f) {\n" " _tfopen_s(&f, name, _T(\"r+\"));\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout.str()); check("void foo(FILE*& f) {\n" " f = tmpfile();\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout.str()); // Write mode @@ -333,37 +339,37 @@ class TestIO : public TestFixture { check("void foo(FILE*& f) {\n" " f = _wfreopen(name, L\"r\", f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); check("void foo(FILE*& f) {\n" " f = _tfreopen(name, _T(\"r\"), f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); check("void foo(FILE*& f) {\n" " f = _tfreopen(name, _T(\"r\"), f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); check("void foo(FILE*& f) {\n" " f = _wfreopen_s(&f, name, L\"r\", f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); check("void foo(FILE*& f) {\n" " f = _tfreopen_s(&f, name, _T(\"r\"), f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); check("void foo(FILE*& f) {\n" " f = _tfreopen_s(&f, name, _T(\"r\"), f);\n" " fwrite(buffer, 5, 6, f);\n" - "}", false, false, Platform::Type::Win32W); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:3]: (error) Write operation on a file that was opened only for reading.\n", errout.str()); // Crash tests @@ -702,30 +708,30 @@ class TestIO : public TestFixture { check("void foo()\n" "{\n" " fflush(stdin);\n" - "}", false, true); + "}", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("[test.cpp:3]: (portability) fflush() called on input stream 'stdin' may result in undefined behaviour on non-linux systems.\n", errout.str()); check("void foo()\n" "{\n" " fflush(stdout);\n" - "}", false, true); + "}", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("", errout.str()); check("void foo(FILE*& f) {\n" " f = fopen(path, \"r\");\n" " fflush(f);\n" - "}", false, true); + "}", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("[test.cpp:3]: (portability) fflush() called on input stream 'f' may result in undefined behaviour on non-linux systems.\n", errout.str()); check("void foo(FILE*& f) {\n" " f = fopen(path, \"w\");\n" " fflush(f);\n" - "}", false, true); + "}", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("", errout.str()); check("void foo(FILE*& f) {\n" " fflush(f);\n" - "}", false, true); + "}", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("", errout.str()); } @@ -829,65 +835,65 @@ class TestIO : public TestFixture { void testFormatStrNoWarn(const char *filename, unsigned int linenr, const char* code, bool cpp = false) { - check(code, true, false, Platform::Type::Unix32, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, emptyString, errout.str()); - check(code, true, false, Platform::Type::Unix64, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, emptyString, errout.str()); - check(code, true, false, Platform::Type::Win32A, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, emptyString, errout.str()); - check(code, true, false, Platform::Type::Win64, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, emptyString, errout.str()); } void testFormatStrWarn(const char *filename, unsigned int linenr, const char* code, const char* testScanfErrString, bool cpp = false) { - check(code, true, false, Platform::Type::Unix32, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrString, errout.str()); - check(code, true, false, Platform::Type::Unix64, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrString, errout.str()); - check(code, true, false, Platform::Type::Win32A, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrString, errout.str()); - check(code, true, false, Platform::Type::Win64, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrString, errout.str()); } void testFormatStrWarnAka(const char *filename, unsigned int linenr, const char* code, const char* testScanfErrAkaString, const char* testScanfErrAkaWin64String, bool cpp = false) { - check(code, true, true, Platform::Type::Unix32, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrAkaString, errout.str()); - check(code, true, true, Platform::Type::Unix64, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrAkaString, errout.str()); - check(code, true, true, Platform::Type::Win32A, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrAkaString, errout.str()); - check(code, true, true, Platform::Type::Win64, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrAkaWin64String, errout.str()); } void testFormatStrWarnAkaWin64(const char *filename, unsigned int linenr, const char* code, const char* testScanfErrAkaWin64String, bool cpp = false) { - check(code, true, true, Platform::Type::Unix32, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, emptyString, errout.str()); - check(code, true, true, Platform::Type::Unix64, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, emptyString, errout.str()); - check(code, true, true, Platform::Type::Win32A, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, emptyString, errout.str()); - check(code, true, true, Platform::Type::Win64, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrAkaWin64String, errout.str()); } void testFormatStrWarnAkaWin32(const char *filename, unsigned int linenr, const char* code, const char* testScanfErrAkaString, bool cpp = false) { - check(code, true, true, Platform::Type::Unix32, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix32, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrAkaString, errout.str()); - check(code, true, true, Platform::Type::Unix64, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Unix64, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrAkaString, errout.str()); - check(code, true, true, Platform::Type::Win32A, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win32A, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, testScanfErrAkaString, errout.str()); - check(code, true, true, Platform::Type::Win64, true, cpp); + check(code, dinit(CheckOptions, $.inconclusive = true, $.portability = true, $.platform = Platform::Type::Win64, $.onlyFormatStr = true, $.cpp = cpp)); assertEquals(filename, linenr, emptyString, errout.str()); } @@ -968,7 +974,7 @@ class TestIO : public TestFixture { " sscanf(input, \"%3s\", output);\n" " sscanf(input, \"%4s\", output);\n" " sscanf(input, \"%5s\", output);\n" - "}", false); + "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Width 5 given in format string (no. 1) is larger than destination buffer 'output[5]', use %4s to prevent overflowing it.\n", errout.str()); check("void foo() {\n" @@ -978,7 +984,7 @@ class TestIO : public TestFixture { " sscanf(input, \"%3s\", output);\n" " sscanf(input, \"%4s\", output);\n" " sscanf(input, \"%5s\", output);\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:5]: (warning, inconclusive) Width 3 given in format string (no. 1) is smaller than destination buffer 'output[5]'.\n" "[test.cpp:7]: (error) Width 5 given in format string (no. 1) is larger than destination buffer 'output[5]', use %4s to prevent overflowing it.\n" "[test.cpp:4]: (warning) sscanf() without field width limits can crash with huge input data.\n", errout.str()); @@ -990,7 +996,7 @@ class TestIO : public TestFixture { " bufT projectId= {0};\n" " const int scanrc=sscanf(line, \"Project(\\\"{%36s}\\\")\", projectId);\n" " sscanf(input, \"%5s\", output);\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:6]: (warning, inconclusive) Width 36 given in format string (no. 1) is smaller than destination buffer 'projectId[2048]'.\n", errout.str()); check("void foo(unsigned int i) {\n" @@ -1059,13 +1065,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%u\", \"s3\");\n" " scanf(\"%u\", L\"s5W\");\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'const wchar_t *'.\n", errout.str()); check("void foo(long l) {\n" " scanf(\"%u\", l);\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %u in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed long'.\n", errout.str()); TEST_SCANF_WARN("%lu","unsigned long","bool"); @@ -1447,13 +1453,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%Ld\", \"s3\");\n" " scanf(\"%Ld\", L\"s5W\");\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'const wchar_t *'.\n", errout.str()); check("void foo(int i) {\n" " scanf(\"%Ld\", i);\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %Ld in format string (no. 1) requires 'long long *' but the argument type is 'signed int'.\n", errout.str()); TEST_SCANF_WARN("%ju", "uintmax_t", "bool"); @@ -1924,13 +1930,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%d\", \"s3\");\n" " scanf(\"%d\", L\"s5W\");\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'const wchar_t *'.\n", errout.str()); check("void foo(long l) {\n" " scanf(\"%d\", l);\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 1) requires 'int *' but the argument type is 'signed long'.\n", errout.str()); TEST_SCANF_WARN("%x", "unsigned int", "bool"); @@ -1968,13 +1974,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%x\", \"s3\");\n" " scanf(\"%x\", L\"s5W\");\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'const wchar_t *'.\n", errout.str()); check("void foo(long l) {\n" " scanf(\"%x\", l);\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed long'.\n", errout.str()); TEST_SCANF_WARN("%f", "float", "bool"); @@ -2008,13 +2014,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%f\", \"s3\");\n" " scanf(\"%f\", L\"s5W\");\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'const wchar_t *'.\n", errout.str()); check("void foo(float f) {\n" " scanf(\"%f\", f);\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %f in format string (no. 1) requires 'float *' but the argument type is 'float'.\n", errout.str()); TEST_SCANF_WARN("%lf", "double", "bool"); @@ -2104,13 +2110,13 @@ class TestIO : public TestFixture { check("void foo() {\n" " scanf(\"%n\", \"s3\");\n" " scanf(\"%n\", L\"s5W\");\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'const wchar_t *'.\n", errout.str()); check("void foo(long l) {\n" " scanf(\"%n\", l);\n" - "}", true); + "}", dinit(CheckOptions, $.inconclusive = true)); ASSERT_EQUALS("[test.cpp:2]: (warning) %n in format string (no. 1) requires 'int *' but the argument type is 'signed long'.\n", errout.str()); check("void g() {\n" // #5104 @@ -2141,13 +2147,13 @@ class TestIO : public TestFixture { const char* result_win64("[test.cpp:5]: (portability) %zd in format string (no. 1) requires 'ssize_t *' but the argument type is 'size_t * {aka unsigned long long *}'.\n" "[test.cpp:6]: (portability) %zd in format string (no. 1) requires 'ssize_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'.\n"); - check(code, false, true, Platform::Type::Unix32); + check(code, dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32)); ASSERT_EQUALS(result, errout.str()); - check(code, false, true, Platform::Type::Unix64); + check(code, dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS(result, errout.str()); - check(code, false, true, Platform::Type::Win32A); + check(code, dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS(result, errout.str()); - check(code, false, true, Platform::Type::Win64); + check(code, dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS(result_win64, errout.str()); } { @@ -2537,56 +2543,56 @@ class TestIO : public TestFixture { check("void foo(size_t s, ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", false, true, Platform::Type::Unix32); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n", errout.str()); check("void foo(std::size_t s, std::ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", false, true, Platform::Type::Unix32); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\n", errout.str()); check("void foo(size_t s, ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", false, true, Platform::Type::Unix64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n", errout.str()); check("void foo(std::size_t s, std::ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", false, true, Platform::Type::Unix64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\n", errout.str()); check("void foo(size_t s, ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", false, true, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n", errout.str()); check("void foo(std::size_t s, std::ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", false, true, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long}'.\n", errout.str()); check("void foo(size_t s, ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", false, true, Platform::Type::Win64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'ptrdiff_t {aka signed long long}'.\n", errout.str()); check("void foo(std::size_t s, std::ptrdiff_t p) {\n" " printf(\"%zd\", s);\n" " printf(\"%tu\", p);\n" - "}", false, true, Platform::Type::Win64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'std::size_t {aka unsigned long long}'.\n" "[test.cpp:3]: (portability) %tu in format string (no. 1) requires 'unsigned ptrdiff_t' but the argument type is 'std::ptrdiff_t {aka signed long long}'.\n", errout.str()); @@ -2595,7 +2601,7 @@ class TestIO : public TestFixture { " printf(\"%lu\", um);\n" " printf(\"%llu\", s);\n" " printf(\"%llu\", um);\n" - "}", false, true, Platform::Type::Win64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long long}'.\n" "[test.cpp:3]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'uintmax_t {aka unsigned long long}'.\n" "[test.cpp:4]: (portability) %llu in format string (no. 1) requires 'unsigned long long' but the argument type is 'size_t {aka unsigned long long}'.\n" @@ -2626,7 +2632,7 @@ class TestIO : public TestFixture { check("void foo(intmax_t im, ptrdiff_t p) {\n" " printf(\"%lld\", im);\n" " printf(\"%lld\", p);\n" - "}", false, true, Platform::Type::Win64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %lld in format string (no. 1) requires 'long long' but the argument type is 'intmax_t {aka signed long long}'.\n" "[test.cpp:3]: (portability) %lld in format string (no. 1) requires 'long long' but the argument type is 'ptrdiff_t {aka signed long long}'.\n", errout.str()); @@ -2935,7 +2941,7 @@ class TestIO : public TestFixture { "void foo() {\n" " printf(\"%zu %Iu %d %f\", v.size(), v.size(), v.size(), v.size());\n" " printf(\"%zu %Iu %d %f\", s.size(), s.size(), s.size(), s.size());\n" - "}\n", false, true, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n" @@ -2946,7 +2952,7 @@ class TestIO : public TestFixture { "void foo() {\n" " printf(\"%zu %Iu %d %f\", v.size(), v.size(), v.size(), v.size());\n" " printf(\"%zu %Iu %d %f\", s.size(), s.size(), s.size(), s.size());\n" - "}\n", false, true, Platform::Type::Win64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long long}'.\n" "[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long long}'.\n" "[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long long}'.\n" @@ -2957,7 +2963,7 @@ class TestIO : public TestFixture { "void foo() {\n" " printf(\"%zu %Iu %d %f\", v.size(), v.size(), v.size(), v.size());\n" " printf(\"%zu %Iu %d %f\", s.size(), s.size(), s.size(), s.size());\n" - "}\n", false, true, Platform::Type::Unix32); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32)); ASSERT_EQUALS("[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n" @@ -2968,7 +2974,7 @@ class TestIO : public TestFixture { "void foo() {\n" " printf(\"%zu %Iu %d %f\", v.size(), v.size(), v.size(), v.size());\n" " printf(\"%zu %Iu %d %f\", s.size(), s.size(), s.size(), s.size());\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'std::size_t {aka unsigned long}'.\n" "[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n" @@ -2979,7 +2985,7 @@ class TestIO : public TestFixture { "void foo() {\n" " printf(\"%zu %Iu %d %f\", v.size(), v.size(), v.size(), v.size());\n" " printf(\"%zu %Iu %d %f\", s.size(), s.size(), s.size(), s.size());\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:4]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:4]: (portability) %f in format string (no. 4) requires 'double' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:5]: (portability) %d in format string (no. 3) requires 'int' but the argument type is 'std::size_t {aka unsigned long}'.\n" @@ -2988,14 +2994,14 @@ class TestIO : public TestFixture { check("class Fred : public std::vector {} v;\n" "void foo() {\n" " printf(\"%d %u %f\", v[0], v[0], v[0]);\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'int'.\n" "[test.cpp:3]: (warning) %f in format string (no. 3) requires 'double' but the argument type is 'int'.\n", errout.str()); check("std::string s;\n" "void foo() {\n" " printf(\"%s %p %u %d %f\", s.c_str(), s.c_str(), s.c_str(), s.c_str(), s.c_str());\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:3]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %d in format string (no. 4) requires 'int' but the argument type is 'const char *'.\n" "[test.cpp:3]: (warning) %f in format string (no. 5) requires 'double' but the argument type is 'const char *'.\n", errout.str()); @@ -3011,7 +3017,7 @@ class TestIO : public TestFixture { " printf(\"%u %u\", array.size(), s);\n" " printf(\"%lu %lu\", array.size(), s);\n" " printf(\"%llu %llu\", array.size(), s);\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:8]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'char *'.\n" "[test.cpp:8]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'char *'.\n" "[test.cpp:8]: (warning) %u in format string (no. 3) requires 'unsigned int' but the argument type is 'char *'.\n" @@ -3035,7 +3041,7 @@ class TestIO : public TestFixture { "char ca[3];\n" "void foo() {\n" " printf(\"%td %zd %d %d %d %d %d %d %d %d %d %d %d\", pt, pt, b, c, sc, uc, s, us, st, pt, pc, cl, ca);\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:13]: (portability) %zd in format string (no. 2) requires 'ssize_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n" "[test.cpp:13]: (portability) %d in format string (no. 9) requires 'int' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:13]: (portability) %d in format string (no. 10) requires 'int' but the argument type is 'ptrdiff_t {aka signed long}'.\n" @@ -3056,7 +3062,7 @@ class TestIO : public TestFixture { "char ca[3];\n" "void foo() {\n" " printf(\"%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\", b, c, sc, uc, s, us, st, pt, pc, cl, ca);\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:13]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'bool'.\n" "[test.cpp:13]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'char'.\n" "[test.cpp:13]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'signed char'.\n" @@ -3083,7 +3089,7 @@ class TestIO : public TestFixture { "char ca[3];\n" "void foo() {\n" " printf(\"%td %zd %d %d %d %d %d %d %d %d %d\", ptf(), ptf(), bf(), cf(), scf(), ucf(), sf(), usf(), stf(), ptf(), pcf());\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:13]: (portability) %zd in format string (no. 2) requires 'ssize_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n" "[test.cpp:13]: (portability) %d in format string (no. 9) requires 'int' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:13]: (portability) %d in format string (no. 10) requires 'int' but the argument type is 'ptrdiff_t {aka signed long}'.\n" @@ -3102,7 +3108,7 @@ class TestIO : public TestFixture { "char ca[3];\n" "void foo() {\n" " printf(\"%ld %ld %ld %ld %ld %ld %ld %ld %ld\", bf(), cf(), scf(), ucf(), sf(), usf(), stf(), ptf(), pcf());\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:13]: (warning) %ld in format string (no. 1) requires 'long' but the argument type is 'bool'.\n" "[test.cpp:13]: (warning) %ld in format string (no. 2) requires 'long' but the argument type is 'char'.\n" "[test.cpp:13]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'signed char'.\n" @@ -3122,7 +3128,7 @@ class TestIO : public TestFixture { " printf(\"%p %d\", b[0], b[0]);\n" " printf(\"%p %d\", c[0], c[0]);\n" " printf(\"%p %d\", s.c_str(), s.c_str());\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:6]: (portability) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:7]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const int *'.\n" "[test.cpp:8]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const struct A *'.\n" @@ -3135,7 +3141,7 @@ class TestIO : public TestFixture { " printf(\"%p %d\", a[0].c_str(), a[0].c_str());\n" " printf(\"%c %p\", b[0], b[0]);\n" " printf(\"%c %p\", s[0], s[0]);\n" - "}\n", false, false, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const char *'.\n" "[test.cpp:6]: (warning) %p in format string (no. 2) requires an address but the argument type is 'char'.\n" "[test.cpp:7]: (warning) %p in format string (no. 2) requires an address but the argument type is 'char'.\n", errout.str()); @@ -3147,28 +3153,28 @@ class TestIO : public TestFixture { "buffer b;\n" "void foo() {\n" " printf(\"%u\", b.size());\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:7]: (portability) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'size_t {aka unsigned long}'.\n", errout.str()); check("DWORD a;\n" "DWORD_PTR b;\n" "void foo() {\n" " printf(\"%u %u\", a, b);\n" - "}\n", false, true, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:4]: (portability) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'DWORD {aka unsigned long}'.\n" "[test.cpp:4]: (portability) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'DWORD_PTR {aka unsigned long}'.\n", errout.str()); check("unsigned long a[] = { 1, 2 };\n" "void foo() {\n" " printf(\"%d %d %x \", a[0], a[0], a[0]);\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned long'.\n" "[test.cpp:3]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned long'.\n" "[test.cpp:3]: (warning) %x in format string (no. 3) requires 'unsigned int' but the argument type is 'unsigned long'.\n", errout.str()); check("void foo (wchar_t c) {\n" // ticket #5051 false positive " printf(\"%c\", c);\n" - "}\n", false, false, Platform::Type::Win64); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("", errout.str()); check("void foo() {\n" @@ -3344,7 +3350,7 @@ class TestIO : public TestFixture { check("void f() {\n" " printf(\"%lu\", sizeof(char));\n" - "}\n", false, true, Platform::Type::Win64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %lu in format string (no. 1) requires 'unsigned long' but the argument type is 'size_t {aka unsigned long long}'.\n", errout.str()); } @@ -4132,7 +4138,7 @@ class TestIO : public TestFixture { " printf(\"%I32d %I32u %I32x\", u32, u32, u32);\n" " printf(\"%I64d %I64u %I64x\", i64, i64, i64);\n" " printf(\"%I64d %I64u %I64x\", u64, u64, u64);\n" - "}", false, true, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'size_t {aka unsigned long}'.\n" "[test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n" "[test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long}'.\n" @@ -4154,7 +4160,7 @@ class TestIO : public TestFixture { " printf(\"%I32d %I32u %I32x\", u32, u32, u32);\n" " printf(\"%I64d %I64u %I64x\", i64, i64, i64);\n" " printf(\"%I64d %I64u %I64x\", u64, u64, u64);\n" - "}", false, true, Platform::Type::Win64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t' but the argument type is 'size_t {aka unsigned long long}'.\n" "[test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long long}'.\n" "[test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t' but the argument type is 'ptrdiff_t {aka signed long long}'.\n" @@ -4199,23 +4205,23 @@ class TestIO : public TestFixture { // ticket #5264 check("void foo(LPARAM lp, WPARAM wp, LRESULT lr) {\n" " printf(\"%Ix %Ix %Ix\", lp, wp, lr);\n" - "}\n", false, true, Platform::Type::Win64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("", errout.str()); check("void foo(LPARAM lp, WPARAM wp, LRESULT lr) {\n" " printf(\"%Ix %Ix %Ix\", lp, wp, lr);\n" - "}\n", false, true, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("", errout.str()); check("void foo(UINT32 a, ::UINT32 b, Fred::UINT32 c) {\n" " printf(\"%d %d %d\", a, b, c);\n" - "};\n", false, true, Platform::Type::Win32A); + "};\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:2]: (portability) %d in format string (no. 1) requires 'int' but the argument type is 'UINT32 {aka unsigned int}'.\n" "[test.cpp:2]: (portability) %d in format string (no. 2) requires 'int' but the argument type is 'UINT32 {aka unsigned int}'.\n", errout.str()); check("void foo(LPCVOID a, ::LPCVOID b, Fred::LPCVOID c) {\n" " printf(\"%d %d %d\", a, b, c);\n" - "};\n", false, true, Platform::Type::Win32A); + "};\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:2]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'const void *'.\n" "[test.cpp:2]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'const void *'.\n", errout.str()); @@ -4225,7 +4231,7 @@ class TestIO : public TestFixture { " printf(\"%zd\", s);\n" " printf(\"%zd%i\", s, i);\n" " printf(\"%zu\", s);\n" - "}", false, true, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long}'.\n", errout.str()); check("void foo() {\n" @@ -4234,7 +4240,7 @@ class TestIO : public TestFixture { " printf(\"%zd\", s);\n" " printf(\"%zd%i\", s, i);\n" " printf(\"%zu\", s);\n" - "}", false, true, Platform::Type::Win64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long long}'.\n", errout.str()); check("void foo() {\n" @@ -4243,7 +4249,7 @@ class TestIO : public TestFixture { " printf(\"%zd\", s);\n" " printf(\"%zd%i\", s, i);\n" " printf(\"%zu\", s);\n" - "}", false, true, Platform::Type::Unix64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("", errout.str()); check("void foo() {\n" @@ -4253,7 +4259,7 @@ class TestIO : public TestFixture { " printf(\"%zd\", s);\n" " printf(\"%zd%i\", s, i);\n" " printf(\"%zu\", s);\n" - "}", false, true, Platform::Type::Win64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:7]: (portability) %zu in format string (no. 1) requires 'size_t' but the argument type is 'SSIZE_T {aka signed long long}'.\n", errout.str()); } @@ -4272,7 +4278,7 @@ class TestIO : public TestFixture { " scanf(\"%I32d %I32u %I32x\", &u32, &u32, &u32);\n" " scanf(\"%I64d %I64u %I64x\", &i64, &i64, &i64);\n" " scanf(\"%I64d %I64u %I64x\", &u64, &u64, &u64);\n" - "}", false, true, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t *' but the argument type is 'size_t * {aka unsigned long *}'.\n" "[test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'.\n" "[test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long *}'.\n" @@ -4296,7 +4302,7 @@ class TestIO : public TestFixture { " scanf(\"%I32d %I32u %I32x\", &u32, &u32, &u32);\n" " scanf(\"%I64d %I64u %I64x\", &i64, &i64, &i64);\n" " scanf(\"%I64d %I64u %I64x\", &u64, &u64, &u64);\n" - "}", false, true, Platform::Type::Win64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:8]: (portability) %Id in format string (no. 1) requires 'ptrdiff_t *' but the argument type is 'size_t * {aka unsigned long long *}'.\n" "[test.cpp:9]: (portability) %Iu in format string (no. 2) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'.\n" "[test.cpp:9]: (portability) %Ix in format string (no. 3) requires 'size_t *' but the argument type is 'ptrdiff_t * {aka signed long long *}'.\n" @@ -4346,7 +4352,7 @@ class TestIO : public TestFixture { " scanf(\"%zd\", &s);\n" " scanf(\"%zd%i\", &s, &i);\n" " scanf(\"%zu\", &s);\n" - "}", false, true, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long *}'.\n", errout.str()); check("void foo() {\n" @@ -4355,7 +4361,7 @@ class TestIO : public TestFixture { " scanf(\"%zd\", &s);\n" " scanf(\"%zd%i\", &s, &i);\n" " scanf(\"%zu\", &s);\n" - "}", false, true, Platform::Type::Win64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:6]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long long *}'.\n", errout.str()); check("void foo() {\n" @@ -4364,7 +4370,7 @@ class TestIO : public TestFixture { " scanf(\"%zd\", &s);\n" " scanf(\"%zd%i\", &s, &i);\n" " scanf(\"%zu\", &s);\n" - "}", false, true, Platform::Type::Unix64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("", errout.str()); check("void foo() {\n" @@ -4374,7 +4380,7 @@ class TestIO : public TestFixture { " scanf(\"%zd\", &s);\n" " scanf(\"%zd%i\", &s, &i);\n" " scanf(\"%zu\", &s);\n" - "}", false, true, Platform::Type::Win64); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win64)); ASSERT_EQUALS("[test.cpp:7]: (portability) %zu in format string (no. 1) requires 'size_t *' but the argument type is 'SSIZE_T * {aka signed long long *}'.\n", errout.str()); } @@ -4385,7 +4391,7 @@ class TestIO : public TestFixture { " String string;\n" " string.Format(\"%I32d\", u32);\n" " string.AppendFormat(\"%I32d\", u32);\n" - "}", false, true, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("", errout.str()); check("void foo() {\n" @@ -4393,7 +4399,7 @@ class TestIO : public TestFixture { " CString string;\n" " string.Format(\"%I32d\", u32);\n" " string.AppendFormat(\"%I32d\", u32);\n" - "}", false, true, Platform::Type::Unix32); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix32)); ASSERT_EQUALS("", errout.str()); check("void foo() {\n" @@ -4402,7 +4408,7 @@ class TestIO : public TestFixture { " string.Format(\"%I32d\", u32);\n" " string.AppendFormat(\"%I32d\", u32);\n" " CString::Format(\"%I32d\", u32);\n" - "}", false, true, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:4]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'.\n" "[test.cpp:5]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'.\n" "[test.cpp:6]: (portability) %I32d in format string (no. 1) requires '__int32' but the argument type is 'unsigned __int32 {aka unsigned int}'.\n", errout.str()); @@ -4413,7 +4419,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " _tprintf_s(_T(\"%d %u\"), u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:4]: (warning) _tprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4422,7 +4428,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " _tprintf_s(_T(\"%d %u\"), u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:4]: (warning) _tprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4431,7 +4437,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " printf_s(\"%d %u\", u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:4]: (warning) printf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4440,7 +4446,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " wprintf_s(L\"%d %u\", u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:4]: (warning) wprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4450,7 +4456,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " _stprintf_s(str, sizeof(str) / sizeof(TCHAR), _T(\"%d %u\"), u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:5]: (warning) _stprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4460,7 +4466,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " _stprintf_s(str, sizeof(str) / sizeof(TCHAR), _T(\"%d %u\"), u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:5]: (warning) _stprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4470,7 +4476,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " sprintf_s(str, sizeof(str), \"%d %u\", u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:5]: (warning) sprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4480,7 +4486,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " sprintf_s(str, \"%d %u\", u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:5]: (warning) sprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4490,7 +4496,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " swprintf_s(str, sizeof(str) / sizeof(wchar_t), L\"%d %u\", u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:5]: (warning) swprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4500,7 +4506,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " swprintf_s(str, L\"%d %u\", u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:5]: (warning) swprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4510,7 +4516,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " _sntprintf_s(str, sizeof(str) / sizeof(TCHAR), _TRUNCATE, _T(\"%d %u\"), u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:5]: (warning) _sntprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4520,7 +4526,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " _sntprintf_s(str, sizeof(str) / sizeof(TCHAR), _TRUNCATE, _T(\"%d %u\"), u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:5]: (warning) _sntprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4530,7 +4536,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " _snprintf_s(str, sizeof(str), _TRUNCATE, \"%d %u\", u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:5]: (warning) _snprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4540,7 +4546,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " _snwprintf_s(str, sizeof(str) / sizeof(wchar_t), _TRUNCATE, L\"%d %u\", u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:5]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:5]: (warning) _snwprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4549,7 +4555,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " _ftprintf_s(fp, _T(\"%d %u\"), u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:4]: (warning) _ftprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4558,7 +4564,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " _ftprintf_s(fp, _T(\"%d %u\"), u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:4]: (warning) _ftprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4567,7 +4573,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " fprintf_s(fp, \"%d %u\", u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:4]: (warning) fprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4576,7 +4582,7 @@ class TestIO : public TestFixture { " int i;\n" " unsigned int u;\n" " fwprintf_s(fp, L\"%d %u\", u, i, 0);\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:4]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'unsigned int'.\n" "[test.cpp:4]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.\n" "[test.cpp:4]: (warning) fwprintf_s format string requires 2 parameters but 3 are given.\n", errout.str()); @@ -4586,7 +4592,7 @@ class TestIO : public TestFixture { " const char * const format = \"%15s%17s%17s%17s%17s\";\n" " sprintf_s(lineBuffer, 600, format, \"type\", \"sum\", \"avg\", \"min\", \"max\");\n" " sprintf_s(lineBuffer, format, \"type\", \"sum\", \"avg\", \"min\", \"max\");\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("", errout.str()); check("void foo() {\n" @@ -4606,7 +4612,7 @@ class TestIO : public TestFixture { " sprintf_s(lineBuffer, 100, format1, \"type\", \"sum\", \"avg\", \"min\", i, 0);\n" " sprintf_s(lineBuffer, 100, format2, \"type\", \"sum\", \"avg\", \"min\", i, 0);\n" " sprintf_s(lineBuffer, 100, format3, \"type\", \"sum\", \"avg\", \"min\", i, 0);\n" - "}\n", true, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.inconclusive = true, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:6]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'.\n" "[test.cpp:6]: (warning) sprintf_s format string requires 5 parameters but 6 are given.\n" "[test.cpp:7]: (warning) %s in format string (no. 5) requires 'char *' but the argument type is 'signed int'.\n" @@ -4640,7 +4646,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " TCHAR str[10];\n" " _tscanf_s(_T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:5]: (warning) _tscanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4650,7 +4656,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " TCHAR str[10];\n" " _tscanf_s(_T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:5]: (warning) _tscanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4660,7 +4666,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " char str[10];\n" " scanf_s(\"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:5]: (warning) scanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4670,7 +4676,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " wchar_t str[10];\n" " wscanf_s(L\"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:5]: (warning) wscanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4679,10 +4685,7 @@ class TestIO : public TestFixture { " char str[8];\n" " scanf_s(\"%8c\", str, sizeof(str));\n" " scanf_s(\"%9c\", str, sizeof(str));\n" - "}\n", - false, - false, - Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:4]: (error) Width 9 given in format string (no. 1) is larger than destination buffer 'str[8]', use %8c to prevent overflowing it.\n", errout.str()); check("void foo() {\n" @@ -4691,7 +4694,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " TCHAR str[10];\n" " _stscanf_s(txt, _T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:6]: (warning) _stscanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4702,7 +4705,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " TCHAR str[10];\n" " _stscanf_s(txt, _T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:6]: (warning) _stscanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4713,7 +4716,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " char str[10];\n" " sscanf_s(txt, \"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:6]: (warning) sscanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4724,7 +4727,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " wchar_t str[10];\n" " swscanf_s(txt, L\"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:6]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:6]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:6]: (warning) swscanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4734,7 +4737,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " TCHAR str[10];\n" " _ftscanf_s(fp, _T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:5]: (warning) _ftscanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4744,7 +4747,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " TCHAR str[10];\n" " _ftscanf_s(fp, _T(\"%s %d %u %[a-z]\"), str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:5]: (warning) _ftscanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4754,7 +4757,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " char str[10];\n" " fscanf_s(fp, \"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32A); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:5]: (warning) fscanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4764,7 +4767,7 @@ class TestIO : public TestFixture { " unsigned int u;\n" " wchar_t str[10];\n" " fwscanf_s(fp, L\"%s %d %u %[a-z]\", str, 10, &u, &i, str, 10, 0)\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("[test.cpp:5]: (warning) %d in format string (no. 2) requires 'int *' but the argument type is 'unsigned int *'.\n" "[test.cpp:5]: (warning) %u in format string (no. 3) requires 'unsigned int *' but the argument type is 'signed int *'.\n" "[test.cpp:5]: (warning) fwscanf_s format string requires 6 parameters but 7 are given.\n", errout.str()); @@ -4772,7 +4775,7 @@ class TestIO : public TestFixture { check("void foo() {\n" " WCHAR msStr1[5] = {0};\n" " wscanf_s(L\"%4[^-]\", msStr1, _countof(msStr1));\n" - "}\n", false, false, Platform::Type::Win32W); + "}\n", dinit(CheckOptions, $.platform = Platform::Type::Win32W)); ASSERT_EQUALS("", errout.str()); } @@ -4780,13 +4783,13 @@ class TestIO : public TestFixture { check("void foo(float f) {\n" " QString string;\n" " string.sprintf(\"%d\", f);\n" - "}", false, false, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'.\n", errout.str()); check("void foo(float f) {\n" " QString string;\n" " string = QString::asprintf(\"%d\", f);\n" - "}", false, false, Platform::Type::Win32A); + "}", dinit(CheckOptions, $.platform = Platform::Type::Win32A)); ASSERT_EQUALS("[test.cpp:3]: (warning) %d in format string (no. 1) requires 'int' but the argument type is 'float'.\n", errout.str()); } @@ -4846,7 +4849,7 @@ class TestIO : public TestFixture { // 8141 check("void f(int i) {\n" " printf(\"%f\", imaxabs(i));\n" - "}\n", false, true, Platform::Type::Unix64); + "}\n", dinit(CheckOptions, $.portability = true, $.platform = Platform::Type::Unix64)); ASSERT_EQUALS("[test.cpp:2]: (portability) %f in format string (no. 1) requires 'double' but the argument type is 'intmax_t {aka signed long}'.\n", errout.str()); } @@ -4881,7 +4884,7 @@ class TestIO : public TestFixture { " auto s = sizeof(int);\n" " printf(\"%zu\", s);\n" " printf(\"%f\", s);\n" - "}\n", false, true); + "}\n", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("[test.cpp:4]: (portability) %f in format string (no. 1) requires 'double' but the argument type is 'size_t {aka unsigned long}'.\n", errout.str()); } @@ -4906,7 +4909,7 @@ class TestIO : public TestFixture { check("void foo(const std::vector& IO, const int* pio) {\n" "const auto Idx = std::distance(&IO.front(), pio);\n" "printf(\"Idx = %td\", Idx);\n" - "}", /*inconclusive*/ false, /*portability*/ true); + "}", dinit(CheckOptions, $.portability = true)); ASSERT_EQUALS("", errout.str()); }