diff --git a/test/testother.cpp b/test/testother.cpp index 4cef19c0575..c8b2a59a04b 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -43,7 +43,9 @@ class TestOther : public TestFixture { TestOther() : TestFixture("TestOther") {} private: - /*const*/ Settings _settings = settingsBuilder().library("std.cfg").build(); + const Settings settings0 = settingsBuilder().library("std.cfg").build(); + /*const*/ Settings settings1 = settingsBuilder().library("std.cfg").severity(Severity::style).severity(Severity::warning).severity(Severity::portability).severity(Severity::performance).build(); + const Settings settings2 = settingsBuilder(settings1).certainty(Certainty::inconclusive).build(); void run() override { mNewTemplate = true; @@ -326,34 +328,39 @@ class TestOther : public TestFixture { TEST_CASE(unionZeroInitBitfields); } + struct CheckOptions + { + CheckOptions() = default; + bool cpp = true; + bool inconclusive = true; + bool verbose = false; + Settings* settings = nullptr; + }; + #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) template - void check_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) { - if (!settings) { - settings = &_settings; + void check_(const char* file, int line, const char (&code)[size], const CheckOptions& opt = make_default_obj{}) { + // TODO: do not modify object passed into + Settings* settings; + if (!opt.settings) { + settings = &settings1; + } + else { + settings = opt.settings; + settings->severity.enable(Severity::style); + settings->severity.enable(Severity::warning); + settings->severity.enable(Severity::portability); + settings->severity.enable(Severity::performance); } - settings->severity.enable(Severity::style); - settings->severity.enable(Severity::warning); - settings->severity.enable(Severity::portability); - settings->severity.enable(Severity::performance); - settings->standards.c = Standards::CLatest; - settings->standards.cpp = Standards::CPPLatest; - settings->certainty.setEnabled(Certainty::inconclusive, inconclusive); - settings->verbose = verbose; + settings->certainty.setEnabled(Certainty::inconclusive, opt.inconclusive); + settings->verbose = opt.verbose; // Tokenize.. - SimpleTokenizer tokenizer(*settings, *this, cpp); + SimpleTokenizer tokenizer(*settings, *this, opt.cpp); ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. runChecks(tokenizer, this); - - (void)runSimpleChecks; // TODO Remove this - } - - template - void check_(const char* file, int line, const char (&code)[size], Settings *s) { - check_(file, line, code, true, true, true, false, s); } struct CheckPOptions @@ -365,16 +372,7 @@ class TestOther : public TestFixture { #define checkP(...) checkP_(__FILE__, __LINE__, __VA_ARGS__) template void checkP_(const char* file, int line, const char (&code)[size], const CheckPOptions& options = make_default_obj()) { - Settings* settings = &_settings; - settings->severity.enable(Severity::style); - settings->severity.enable(Severity::warning); - settings->severity.enable(Severity::portability); - settings->severity.enable(Severity::performance); - settings->standards.c = Standards::CLatest; - settings->standards.cpp = Standards::CPPLatest; - settings->certainty.enable(Certainty::inconclusive); - - SimpleTokenizer2 tokenizer(*settings, *this, code, options.cpp ? "test.cpp" : "test.c"); + SimpleTokenizer2 tokenizer(settings2, *this, code, options.cpp ? "test.cpp" : "test.c"); // Tokenizer.. ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); @@ -387,7 +385,7 @@ class TestOther : public TestFixture { void checkInterlockedDecrement(const char (&code)[size]) { /*const*/ Settings settings = settingsBuilder().platform(Platform::Type::Win32A).build(); - check(code, true, false, true, false, &settings); + check(code, dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); } void emptyBrackets() { @@ -1212,7 +1210,7 @@ class TestOther : public TestFixture { " else if(b);\n" " else if(c);\n" " else;\n" - "}", true, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } @@ -1424,7 +1422,7 @@ class TestOther : public TestFixture { " currtime = time(&dummy);\n" " if (currtime > t) {}\n" " }\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:2:12]: (style) The scope of the variable 'currtime' can be reduced. [variableScope]\n", errout_str()); } @@ -1477,7 +1475,7 @@ class TestOther : public TestFixture { " s.i = 0;\n" " g(e, s);\n" " }\n" - "}\n", false); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:4:12]: (style) The scope of the variable 'e' can be reduced. [variableScope]\n" "[test.c:5:14]: (style) The scope of the variable 's' can be reduced. [variableScope]\n", errout_str()); @@ -1736,7 +1734,7 @@ class TestOther : public TestFixture { " else{\n" " for( i = 0U; i < 5U; i++ ) {}\n" " }\n" - "}\n", true, false); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\n", errout_str()); } @@ -1751,7 +1749,7 @@ class TestOther : public TestFixture { " for( i = 0U; i < 5U; i++ ) {}\n" " }\n" " }\n" - "}\n", true, false); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:2:14]: (style) The scope of the variable 'i' can be reduced. [variableScope]\n", errout_str()); } @@ -2242,10 +2240,17 @@ class TestOther : public TestFixture { ASSERT_EQUALS("", errout_str()); } + struct CheckInvalidPointerCastOptions + { + CheckInvalidPointerCastOptions() = default; + bool portability = true; + bool inconclusive = false; + }; + #define checkInvalidPointerCast(...) checkInvalidPointerCast_(__FILE__, __LINE__, __VA_ARGS__) template - void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], bool portability = true, bool inconclusive = false) { - /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, portability).certainty(Certainty::inconclusive, inconclusive).build(); + void checkInvalidPointerCast_(const char* file, int line, const char (&code)[size], const CheckInvalidPointerCastOptions& opt = make_default_obj{}) { + /*const*/ Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability, opt.portability).certainty(Certainty::inconclusive, opt.inconclusive).build(); settings.platform.defaultSign = 's'; // Tokenize.. @@ -2304,24 +2309,24 @@ class TestOther : public TestFixture { checkInvalidPointerCast("void test(float* data) {\n" " f.write((char*)data,sizeof(float));\n" - "}", true, false); + "}"); ASSERT_EQUALS("", errout_str()); checkInvalidPointerCast("void test(float* data) {\n" " f.write((char*)data,sizeof(float));\n" - "}", true, true); // #3639 + "}", dinit(CheckInvalidPointerCastOptions, $.inconclusive = true)); // #3639 ASSERT_EQUALS("[test.cpp:2:13]: (portability, inconclusive) Casting from float * to signed char * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("long long* test(float* f) {\n" " return (long long*)f;\n" - "}", false); + "}", dinit(CheckInvalidPointerCastOptions, $.portability = false)); ASSERT_EQUALS("", errout_str()); checkInvalidPointerCast("long long* test(float* f, char* c) {\n" " foo((long long*)f);\n" " return reinterpret_cast(c);\n" - "}", true); + "}"); ASSERT_EQUALS("[test.cpp:2:9]: (portability) Casting from float * to signed long long * is not portable due to different binary data representations on different platforms. [invalidPointerCast]\n", errout_str()); checkInvalidPointerCast("Q_DECLARE_METATYPE(int*)"); // #4135 - don't crash @@ -2541,7 +2546,7 @@ class TestOther : public TestFixture { "}\n"); ASSERT_EQUALS("[test.cpp:1:42]: (performance) Function parameter 't' should be passed by const reference. [passedByValue]\n", errout_str()); - /*const*/ Settings settings0 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build(); + /*const*/ Settings settingsUnix64 = settingsBuilder(settings0).platform(Platform::Type::Unix64).build(); check("struct S {\n" // #12138 " union {\n" " int a = 0;\n" @@ -2558,7 +2563,7 @@ class TestOther : public TestFixture { "};\n" "void f(S s) {\n" " if (s.x > s.y) {}\n" - "}\n", /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings0); + "}\n", dinit(CheckOptions, $.settings = &settingsUnix64)); ASSERT_EQUALS("", errout_str()); check("struct S { std::list l; };\n" // #12147 @@ -2598,10 +2603,10 @@ class TestOther : public TestFixture { check("void f(const std::array a[]) {}\n"); // #13524 ASSERT_EQUALS("", errout_str()); - /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build(); + /*const*/ Settings settingsWin64 = settingsBuilder().platform(Platform::Type::Win64).build(); check("using ui64 = unsigned __int64;\n" "ui64 Test(ui64 one, ui64 two) { return one + two; }\n", - /*cpp*/ true, /*inconclusive*/ true, /*runSimpleChecks*/ true, /*verbose*/ false, &settings1); + dinit(CheckOptions, $.settings = &settingsWin64)); ASSERT_EQUALS("", errout_str()); } @@ -2745,12 +2750,12 @@ class TestOther : public TestFixture { "};\n" "void f(X x) {}"; - /*const*/ Settings s32 = settingsBuilder(_settings).platform(Platform::Type::Unix32).build(); - check(code, &s32); + /*const*/ Settings s32 = settingsBuilder(settings0).platform(Platform::Type::Unix32).build(); + check(code, dinit(CheckOptions, $.settings = &s32)); ASSERT_EQUALS("[test.cpp:5:10]: (performance) Function parameter 'x' should be passed by const reference. [passedByValue]\n", errout_str()); - /*const*/ Settings s64 = settingsBuilder(_settings).platform(Platform::Type::Unix64).build(); - check(code, &s64); + /*const*/ Settings s64 = settingsBuilder(settings0).platform(Platform::Type::Unix64).build(); + check(code, dinit(CheckOptions, $.settings = &s64)); ASSERT_EQUALS("", errout_str()); } @@ -4796,7 +4801,7 @@ class TestOther : public TestFixture { " case 3:\n" " strcpy(str, \"b'\");\n" " }\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); TODO_ASSERT_EQUALS("[test.cpp:6] -> [test.cpp:8]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", "", errout_str()); @@ -4827,7 +4832,7 @@ class TestOther : public TestFixture { " strcpy(str, \"b'\");\n" " z++;\n" " }\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); TODO_ASSERT_EQUALS("[test.cpp:7] -> [test.cpp:10]: (style) Buffer 'str' is being written before its old content has been used. 'break;' missing?\n", "", errout_str()); @@ -4856,7 +4861,7 @@ class TestOther : public TestFixture { " case 3:\n" " strcpy(str, \"b'\");\n" " }\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // Ticket #5158 "segmentation fault (valid code)" @@ -4870,7 +4875,7 @@ class TestOther : public TestFixture { "} deflate_state;\n" "void f(deflate_state *s) {\n" " s->dyn_ltree[0].fc.freq++;\n" - "}\n", true, false, false); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // Ticket #6132 "crash: daca: kvirc CheckOther::checkRedundantAssignment()" @@ -4880,7 +4885,7 @@ class TestOther : public TestFixture { "} else {\n" "KviKvsScript :: run ( m_szCompletionCallback , out ? out : ( g_pApp . activeConsole ( ) ) , & vParams ) ;\n" "}\n" - "}\n", true, false, true); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -5041,7 +5046,7 @@ class TestOther : public TestFixture { " y++;\n" " }\n" " bar(y);\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5095,7 +5100,7 @@ class TestOther : public TestFixture { " y--;\n" " }\n" " bar(y);\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("void foo()\n" "{\n" @@ -5451,20 +5456,20 @@ class TestOther : public TestFixture { " continue;\n" " }\n" " }\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:5:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo(int a) {\n" " return 0;\n" " return(a-1);\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo(int a) {\n" " A:" " return(0);\n" " goto A;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); constexpr char xmldata[] = "\n" @@ -5479,7 +5484,7 @@ class TestOther : public TestFixture { check("void foo() {\n" " exit(0);\n" " break;\n" - "}", true, false, false, false, &settings); + "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("class NeonSession {\n" @@ -5488,16 +5493,16 @@ class TestOther : public TestFixture { "void NeonSession::exit()\n" "{\n" " SAL_INFO(\"ucb.ucp.webdav\", \"neon commands cannot be aborted\");\n" - "}", true, false, false, false, &settings); + "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("", errout_str()); check("void NeonSession::exit()\n" "{\n" " SAL_INFO(\"ucb.ucp.webdav\", \"neon commands cannot be aborted\");\n" - "}", true, false, false, false, &settings); + "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("", errout_str()); - check("void foo() { xResAccess->exit(); }", true, false, false, false, &settings); + check("void foo() { xResAccess->exit(); }", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("", errout_str()); check("void foo(int a)\n" @@ -5511,7 +5516,7 @@ class TestOther : public TestFixture { " c++;\n" " break;\n" " }\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:7:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo(int a)\n" @@ -5535,7 +5540,7 @@ class TestOther : public TestFixture { " break;\n" " }\n" " }\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo(int a)\n" @@ -5547,7 +5552,7 @@ class TestOther : public TestFixture { " }\n" " a+=2;\n" " }\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:6:13]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo(int a)\n" @@ -5564,44 +5569,44 @@ class TestOther : public TestFixture { check("int foo() {\n" " throw 0;\n" " return 1;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo() {\n" " throw 0;\n" " return;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo() {\n" " throw = 0;\n" " return 1;\n" - "}", false, false, false); + "}", dinit(CheckOptions, $.cpp = false, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int foo() {\n" " return 0;\n" " return 1;\n" - "}", true, false, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("int foo() {\n" " return 0;\n" " foo();\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", errout_str()); check("int foo(int unused) {\n" " return 0;\n" " (void)unused;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int foo(int unused1, int unused2) {\n" " return 0;\n" " (void)unused1;\n" " (void)unused2;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int foo(int unused1, int unused2) {\n" @@ -5609,7 +5614,7 @@ class TestOther : public TestFixture { " (void)unused1;\n" " (void)unused2;\n" " foo();\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:5:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", errout_str()); check("int foo() {\n" @@ -5627,7 +5632,7 @@ class TestOther : public TestFixture { " return 0;\n" " }\n" " return 124;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); check("void foo() {\n" @@ -5635,7 +5640,7 @@ class TestOther : public TestFixture { " return;\n" " break;\n" " }\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:4:9]: (style) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); // #5707 @@ -5646,14 +5651,14 @@ class TestOther : public TestFixture { " }\n" " return 0;\n" " j=2;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:7:5]: (style) Statements following 'return' will never be executed. [unreachableCode]\n", errout_str()); check("int foo() {\n" " return 0;\n" " label:\n" " throw 0;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:3]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str()); check("struct A {\n" @@ -5695,23 +5700,21 @@ class TestOther : public TestFixture { " return 0;\n" "\n" // #endif " return 1;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int foo() {\n" "\n" // #ifdef A " return 0;\n" "\n" // #endif " return 1;\n" - "}", true, true, false); + "}"); ASSERT_EQUALS("[test.cpp:5:5]: (style, inconclusive) Consecutive return, break, continue, goto or throw statements are unnecessary. [duplicateBreak]\n", errout_str()); // #4711 lambda functions check("int f() {\n" " return g([](int x){(void)x+1; return x;});\n" "}", - true, - false, - false); + dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // #4756 @@ -5725,7 +5728,7 @@ class TestOther : public TestFixture { " __asm__ (\"rorw $8, %w0\" : \"=r\" (__v) : \"0\" (__x) : \"cc\");\n" " (void)__v;\n" " }));\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // #6008 @@ -5734,7 +5737,7 @@ class TestOther : public TestFixture { " int sum = a_ + b_;\n" " return sum;\n" " };\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // #5789 @@ -5742,20 +5745,20 @@ class TestOther : public TestFixture { " uint64_t enter, exit;\n" " uint64_t events;\n" " per_state_info() : enter(0), exit(0), events(0) {}\n" - "};", true, false, false); + "};", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // #6664 check("void foo() {\n" " (beat < 100) ? (void)0 : exit(0);\n" " bar();\n" - "}", true, false, false, false, &settings); + "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("", errout_str()); check("void foo() {\n" " (beat < 100) ? exit(0) : (void)0;\n" " bar();\n" - "}", true, false, false, false, &settings); + "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("", errout_str()); // #8261 @@ -5763,7 +5766,7 @@ class TestOther : public TestFixture { TODO_ASSERT_THROW(check("void foo() {\n" " (beat < 100) ? (void)0 : throw(0);\n" " bar();\n" - "}", true, false, false, false, &settings), InternalError); + "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)), InternalError); //ASSERT_EQUALS("", errout_str()); check("int foo() {\n" @@ -5940,7 +5943,7 @@ class TestOther : public TestFixture { " }\n" " var = 42;\n" " return ret();\n" - "}\n", /*cpp*/ false); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" // #13516 @@ -6394,7 +6397,7 @@ class TestOther : public TestFixture { " b = 300\n" " };\n" "};\n" - "const int DFLT_TIMEOUT = A::b % 1000000 ;\n", true, false, false); + "const int DFLT_TIMEOUT = A::b % 1000000 ;\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } @@ -6519,10 +6522,10 @@ class TestOther : public TestFixture { " do_something();\n" "}\n"; - check(code, true); + check(code); ASSERT_EQUALS("[test.cpp:7:5]: (style) Instance of 'cb_watch_bool' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); - check(code, false); + check(code, dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); // Ticket #2639 @@ -6564,7 +6567,7 @@ class TestOther : public TestFixture { " do_something();\n" "}\n"; - check(code, true); + check(code); ASSERT_EQUALS("", errout_str()); } @@ -6577,7 +6580,7 @@ class TestOther : public TestFixture { " }\n" " Foo(char x, int y) { }\n" "};\n"; - check(code, true); + check(code); ASSERT_EQUALS("[test.cpp:4:5]: (style) Instance of 'Foo' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); } @@ -6592,7 +6595,7 @@ class TestOther : public TestFixture { " int{ i };\n" " int{ g() };\n" // don't warn " g();\n" - "}\n", true); + "}\n"); ASSERT_EQUALS("[test.cpp:3:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\n" "[test.cpp:4:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\n" "[test.cpp:6:5]: (style) Instance of 'int' object is destroyed immediately. [unusedScopedObject]\n" @@ -6602,19 +6605,19 @@ class TestOther : public TestFixture { check("void f(int j) {\n" " for (; bool(j); ) {}\n" - "}\n", true); + "}\n"); ASSERT_EQUALS("", errout_str()); check("void g() {\n" " float (f);\n" " float (*p);\n" - "}\n", true); + "}\n"); ASSERT_EQUALS("", errout_str()); check("int f(int i) {\n" " void();\n" " return i;\n" - "}\n", true); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -6627,7 +6630,7 @@ class TestOther : public TestFixture { "int f() {\n" " M::N::S();\n" " return 0;\n" - "}\n", true); + "}\n"); ASSERT_EQUALS("[test.cpp:7:11]: (style) Instance of 'M::N::S' object is destroyed immediately. [unusedScopedObject]\n", errout_str()); check("void f() {\n" // #10057 @@ -6635,7 +6638,7 @@ class TestOther : public TestFixture { " std::string{ \"abc\" };\n" " std::pair(1, 2);\n" " (void)0;\n" - "}\n", true); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\n" "[test.cpp:3:10]: (style) Instance of 'std::string' object is destroyed immediately. [unusedScopedObject]\n" "[test.cpp:4:10]: (style) Instance of 'std::pair' object is destroyed immediately. [unusedScopedObject]\n", @@ -6652,7 +6655,7 @@ class TestOther : public TestFixture { " std::scoped_lock(m);\n" " }\n" " std::mutex m;\n" - "}\n", true); + "}\n"); ASSERT_EQUALS("[test.cpp:3:14]: (style) Instance of 'std::lock_guard' object is destroyed immediately. [unusedScopedObject]\n" "[test.cpp:6:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\n" "[test.cpp:9:14]: (style) Instance of 'std::scoped_lock' object is destroyed immediately. [unusedScopedObject]\n", @@ -6661,7 +6664,7 @@ class TestOther : public TestFixture { check("struct S { int i; };\n" "namespace {\n" " S s() { return ::S{42}; }\n" - "}\n", true); + "}\n"); ASSERT_EQUALS("", errout_str()); } @@ -6674,7 +6677,7 @@ class TestOther : public TestFixture { "void t0() { f() = {}; }\n" "void t1() { g() = {}; }\n" "void t2() { h() = {}; }\n" - "void t3() { *i() = {}; }\n", true); + "void t3() { *i() = {}; }\n"); ASSERT_EQUALS("[test.cpp:6:19]: (style) Instance of 'S' object is destroyed immediately, assignment has no effect. [unusedScopedObject]\n", errout_str()); } @@ -6718,7 +6721,7 @@ class TestOther : public TestFixture { check("void f(char c) {\n" " printf(\"%i\", a + b ? 1 : 2);\n" - "}",true,false,false); + "}",dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:2:24]: (style) Clarify calculation precedence for '+' and '?'. [clarifyCalculation]\n", errout_str()); check("void f() {\n" @@ -6912,7 +6915,7 @@ class TestOther : public TestFixture { " else\n" " ret = (unsigned char)value;\n" " return ret;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -7221,11 +7224,7 @@ class TestOther : public TestFixture { // make sure there are not "same expression" fp when there are different casts check("void f(long x) { if ((int32_t)x == (int64_t)x) {} }", - true, // filename - false, // inconclusive - false, // runSimpleChecks - false, // verbose - nullptr // settings + dinit(CheckOptions, $.inconclusive = false) ); ASSERT_EQUALS("", errout_str()); @@ -7280,7 +7279,7 @@ class TestOther : public TestFixture { check("void f() {\n" " enum { Four = 4 };\n" " if (Four == 4) {}" - "}", true, true, false); + "}"); ASSERT_EQUALS("[test.cpp:3:14]: (style) The comparison 'Four == 4' is always true. [knownConditionTrueFalse]\n", errout_str()); @@ -7293,7 +7292,7 @@ class TestOther : public TestFixture { check("void f() {\n" " enum { Four = 4 };\n" " _Static_assert(Four == 4, \"\");\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" @@ -7306,7 +7305,7 @@ class TestOther : public TestFixture { " enum { FourInEnumOne = 4 };\n" " enum { FourInEnumTwo = 4 };\n" " if (FourInEnumOne == FourInEnumTwo) {}\n" - "}", true, true, false); + "}"); ASSERT_EQUALS("[test.cpp:4:23]: (style) The comparison 'FourInEnumOne == FourInEnumTwo' is always true because 'FourInEnumOne' and 'FourInEnumTwo' represent the same value. [knownConditionTrueFalse]\n", errout_str()); @@ -7345,7 +7344,7 @@ class TestOther : public TestFixture { check("float f(float x) { return x-x; }"); // ticket #4485 (Inf) ASSERT_EQUALS("", errout_str()); - check("float f(float x) { return (X double)x == (X double)x; }", true, false, false); + check("float f(float x) { return (X double)x == (X double)x; }", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("struct X { float f; };\n" @@ -7419,7 +7418,7 @@ class TestOther : public TestFixture { check("void foo() {\n" " if ((mystrcmp(a, b) == 0) || (mystrcmp(a, b) == 0)) {}\n" - "}", true, false, true, false, &settings); + "}", dinit(CheckOptions, $.inconclusive = false, $.settings = &settings)); ASSERT_EQUALS("[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); check("void GetValue() { return rand(); }\n" @@ -7460,7 +7459,7 @@ class TestOther : public TestFixture { check("void f(A *src) {\n" " if (dynamic_cast(src) || dynamic_cast(src)) {}\n" - "}\n", true, false, false); // don't run simplifications + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:2:31]: (style) Same expression on both sides of '||'. [duplicateExpression]\n", errout_str()); // #5819 @@ -8055,18 +8054,18 @@ class TestOther : public TestFixture { const char code[] = "void foo(bool flag) {\n" " bar( (flag) ? ~0u : ~0ul);\n" "}"; - /*const*/ Settings settings = _settings; + /*const*/ Settings settings = settings0; settings.platform.sizeof_int = 4; settings.platform.int_bit = 32; settings.platform.sizeof_long = 4; settings.platform.long_bit = 32; - check(code, &settings); + check(code, dinit(CheckOptions, $.settings = &settings)); ASSERT_EQUALS("[test.cpp:2:21]: (style) Same value in both branches of ternary operator. [duplicateValueTernary]\n", errout_str()); settings.platform.sizeof_long = 8; settings.platform.long_bit = 64; - check(code, &settings); + check(code, dinit(CheckOptions, $.settings = &settings)); ASSERT_EQUALS("", errout_str()); } } @@ -8809,9 +8808,9 @@ class TestOther : public TestFixture { const char code[] = "void foo(unsigned int x) {\n" " if (x < 0) {}\n" "}"; - check(code, true, false, true, false); + check(code, dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); - check(code, true, false, true, true); + check(code, dinit(CheckOptions, $.inconclusive = false, $.verbose = true)); ASSERT_EQUALS("[test.cpp:2:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); } @@ -8830,9 +8829,9 @@ class TestOther : public TestFixture { " int y = 0;\n" " if (x < y) {}\n" "}"; - check(code, true, false, true, false); + check(code, dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); - check(code, true, false, true, true); + check(code, dinit(CheckOptions, $.inconclusive = false, $.verbose = true)); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:9]: (style) Checking if unsigned expression 'x' is less than zero. [unsignedLessThanZero]\n", errout_str()); } check("void foo(unsigned x) {\n" @@ -8991,9 +8990,9 @@ class TestOther : public TestFixture { " if (x <= n);\n" "}\n" "foo<0>();"; - check(code, true, false); + check(code, dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); - check(code, true, true); + check(code); ASSERT_EQUALS("", errout_str()); } @@ -9015,12 +9014,12 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:3:13]: (style) Checking if unsigned expression 'value' is less than zero. [unsignedLessThanZero]\n", errout_str()); // #9040 - /*const*/ Settings settings1 = settingsBuilder().platform(Platform::Type::Win64).build(); + /*const*/ Settings settingsWin64 = settingsBuilder().platform(Platform::Type::Win64).build(); check("using BOOL = unsigned;\n" "int i;\n" "bool f() {\n" " return i >= 0;\n" - "}\n", &settings1); + "}\n", dinit(CheckOptions, $.settings = &settingsWin64)); ASSERT_EQUALS("", errout_str()); // #10612 @@ -9062,9 +9061,9 @@ class TestOther : public TestFixture { " int y = 0;\n" " if (x >= y) {}\n" "}"; - check(code, true, false, true, false); + check(code, dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n", errout_str()); - check(code, true, false, true, true); + check(code, dinit(CheckOptions, $.inconclusive = false, $.verbose = true)); ASSERT_EQUALS("[test.cpp:2:11] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is not. [pointerPositive]\n", errout_str()); } check("void foo(const int* x) {\n" @@ -9083,9 +9082,9 @@ class TestOther : public TestFixture { " if (x < y) {}\n" "}"; - check(code, true, false, true, false); + check(code, dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n", errout_str()); - check(code, true, false, true, true); + check(code, dinit(CheckOptions, $.inconclusive = false, $.verbose = true)); ASSERT_EQUALS("[test.cpp:2:16] -> [test.cpp:3:9]: (style) A pointer can not be negative so it is either pointless or an error to check if it is. [pointerLessThanZero]\n", errout_str()); } @@ -9559,9 +9558,9 @@ class TestOther : public TestFixture { " tok->str(tok->strAt(2));\n" " }\n" "}"; - check(code5618, true, true); + check(code5618); ASSERT_EQUALS("", errout_str()); - check(code5618, true, false); + check(code5618, dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // #5890 - crash: wesnoth desktop_util.cpp / unicode.hpp @@ -9581,7 +9580,7 @@ class TestOther : public TestFixture { " \n" "void foo() {\n" " const CD cd(CD::getOne());\n" - "}", true, true); + "}"); ASSERT_EQUALS("", errout_str()); check("struct S {\n" // #10545 @@ -9594,7 +9593,7 @@ class TestOther : public TestFixture { " if (i != 0)\n" " return old;\n" " return {};\n" - "}", true, /*inconclusive*/ true); + "}"); ASSERT_EQUALS("", errout_str()); check("struct X { int x; };\n" // #10191 @@ -9612,7 +9611,7 @@ class TestOther : public TestFixture { " modify();\n" " return x.x;\n" " }\n" - "};\n", true, /*inconclusive*/ true); + "};\n"); ASSERT_EQUALS("", errout_str()); // #10704 @@ -10434,7 +10433,7 @@ class TestOther : public TestFixture { " u.l1 = 1;\n" " lTotal += u.b.b1;\n" " u.l1 = 2;\n" //Should not show RedundantAssignment - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // Ticket #5115 "redundantAssignment when using a union" @@ -10452,7 +10451,7 @@ class TestOther : public TestFixture { " } u;\n" " u.l1 = 1;\n" " u.l1 = 2;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:13:10] -> [test.cpp:14:10]: (style) Variable 'u.l1' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); // Ticket #10093 "redundantAssignment when using a union" @@ -10476,7 +10475,7 @@ class TestOther : public TestFixture { " m.u16.ab = 47;\n" " m.u16.cd = 0;\n" " m.u16.ab = m.u32.abcd / 53;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // Ticket #10093 "redundantAssignment when using a union" @@ -10494,7 +10493,7 @@ class TestOther : public TestFixture { " u.as_int = 42;\n" " fn(&u.as_char[0], 4);\n" " u.as_int = 0;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // Ticket #5115 "redundantAssignment when using a union" @@ -10505,7 +10504,7 @@ class TestOther : public TestFixture { " } addr;\n" " addr.s8 = ptr;\n" " addr.u64 += 8;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("struct S {\n" // #12895 @@ -10540,7 +10539,7 @@ class TestOther : public TestFixture { " }\n" " catch (const uno::Exception&) {\n" " }\n" - "}", true, true); + "}"); ASSERT_EQUALS("", errout_str()); check("void ConvertBitmapData(sal_uInt16 nDestBits) {\n" @@ -10549,7 +10548,7 @@ class TestOther : public TestFixture { " BitmapBuffer aDstBuf;\n" " aSrcBuf.mnBitCount = nDestBits;\n" " bConverted = ::ImplFastBitmapConversion( aDstBuf, aSrcBuf, aTwoRects );\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3:24] -> [test.c:5:24]: (style) Variable 'aSrcBuf.mnBitCount' is reassigned a value before the old one has been used. [redundantAssignment]\n", errout_str()); check("void ConvertBitmapData(sal_uInt16 nDestBits) {\n" " BitmapBuffer aSrcBuf;\n" @@ -11163,32 +11162,32 @@ class TestOther : public TestFixture { " if (a < 0)\n" " return a++,\n" " do_something();\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\n", "", errout_str()); check("int fun(int a) {\n" " if (a < 0)\n" " return a++, do_something();\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int fun(int a) {\n" " if (a < 0)\n" " return a+5,\n" " do_something();\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); TODO_ASSERT_EQUALS("[test.cpp:3]: (style) Comma is used in return statement. The comma can easily be misread as a ';'.\n", "", errout_str()); check("int fun(int a) {\n" " if (a < 0)\n" " return a+5, do_something();\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("int fun(int a) {\n" " if (a < 0)\n" " return c::b;\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); // #4943 take care of C++11 initializer lists @@ -11199,7 +11198,7 @@ class TestOther : public TestFixture { " { \"2\" },\n" " { \"3\" }\n" " };\n" - "}", true, false, false); + "}", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } @@ -11215,7 +11214,7 @@ class TestOther : public TestFixture { " explicit B(A a) : a(std::move(a)) {}\n" " void Init(A _a) { a = std::move(_a); }\n" " A a;" - "};", true, false, true); + "};", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("struct A\n" @@ -11228,7 +11227,7 @@ class TestOther : public TestFixture { " explicit B(A a) : a{std::move(a)} {}\n" " void Init(A _a) { a = std::move(_a); }\n" " A a;" - "};", true, false, true); + "};", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("struct A\n" @@ -11242,7 +11241,7 @@ class TestOther : public TestFixture { " void Init(A _a) { a = std::move(_a); }\n" " A a;" " A a2;" - "};", true, false, true); + "};", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); check("struct A\n" @@ -11256,7 +11255,7 @@ class TestOther : public TestFixture { " void Init(A _a) { a = std::move(_a); }\n" " A a;" " A a2;" - "};", true, false, true); + "};", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\n", errout_str()); check("struct A\n" @@ -11270,7 +11269,7 @@ class TestOther : public TestFixture { " void Init(A _a) { a = std::move(_a); }\n" " A a;" " A a2;" - "};", true, false, true); + "};", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:8:14]: (performance) Function parameter 'a2' should be passed by const reference. [passedByValue]\n", errout_str()); check("std::map m;\n" // #10817 @@ -11313,7 +11312,7 @@ class TestOther : public TestFixture { " int i1 : 16;\n" " unsigned short u16;\n" "};\n" - "void f(S s) {}\n", true, true, true, false, &settingsUnix32); + "void f(S s) {}\n", dinit(CheckOptions, $.settings = &settingsUnix32)); ASSERT_EQUALS("", errout_str()); } @@ -11362,12 +11361,12 @@ class TestOther : public TestFixture { void redundantPointerOp() { check("int *f(int *x) {\n" " return &*x;\n" - "}\n", true, true); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (style) Redundant pointer operation on 'x' - it's already a pointer. [redundantPointerOp]\n", errout_str()); check("int *f(int *y) {\n" " return &(*y);\n" - "}\n", true, true); + "}\n"); ASSERT_EQUALS("[test.cpp:2:12]: (style) Redundant pointer operation on 'y' - it's already a pointer. [redundantPointerOp]\n", errout_str()); check("int f() {\n" // #10991 @@ -11375,18 +11374,18 @@ class TestOther : public TestFixture { " int result1 = *(&value);\n" " int result2 = *&value;\n" " return result1 + result2;\n" - "}\n", true, true); + "}\n"); ASSERT_EQUALS("[test.cpp:3:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\n" "[test.cpp:4:19]: (style) Redundant pointer operation on 'value' - it's already a variable. [redundantPointerOp]\n", errout_str()); check("void f(int& a, int b) {\n" " *(&a) = b;\n" - "}\n", true, true); + "}\n"); ASSERT_EQUALS("[test.cpp:2:5]: (style) Redundant pointer operation on 'a' - it's already a variable. [redundantPointerOp]\n", errout_str()); - check("void f(int**& p) {}\n", true, true); + check("void f(int**& p) {}\n"); ASSERT_EQUALS("", errout_str()); checkP("#define RESTORE(ORIG, COPY) { *ORIG = *COPY; }\n" @@ -11398,38 +11397,38 @@ class TestOther : public TestFixture { // no warning for bitwise AND check("void f(const int *b) {\n" " int x = 0x20 & *b;\n" - "}\n", true, true); + "}\n"); ASSERT_EQUALS("", errout_str()); // No message for double pointers to structs check("void f(struct foo **my_struct) {\n" " char **pass_to_func = &(*my_struct)->buf;\n" - "}\n", true, true); + "}\n"); ASSERT_EQUALS("", errout_str()); // another double pointer to struct - with an array check("void f(struct foo **my_struct) {\n" " char **pass_to_func = &(*my_struct)->buf[10];\n" - "}\n", true, true); + "}\n"); ASSERT_EQUALS("", errout_str()); // double pointer to array check("void f(char **ptr) {\n" " int *x = &(*ptr)[10];\n" - "}\n", true, true); + "}\n"); ASSERT_EQUALS("[test.cpp:2:10]: (style) Variable 'x' can be declared as pointer to const [constVariablePointer]\n", errout_str()); // function calls check("void f(Mutex *mut) {\n" " pthread_mutex_lock(&*mut);\n" - "}\n", true, false); + "}\n", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:2:24]: (style) Redundant pointer operation on 'mut' - it's already a pointer. [redundantPointerOp]\n", errout_str()); // make sure we got the AST match for "(" right check("void f(char *ptr) {\n" " if (&*ptr == NULL)\n" " return;\n" - "}\n", true, true); + "}\n"); ASSERT_EQUALS("[test.cpp:2:9]: (style) Redundant pointer operation on 'ptr' - it's already a pointer. [redundantPointerOp]\n", errout_str()); // no warning for macros @@ -11450,7 +11449,7 @@ class TestOther : public TestFixture { void test_isSameExpression() { // see #5738 check("bool isInUnoIncludeFile(StringRef name) {" " return name.startswith(SRCDIR \"/com/\") || name.startswith(SRCDIR \"/uno/\");\n" - "};", true, false); + "};", dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("", errout_str()); } @@ -11765,53 +11764,40 @@ class TestOther : public TestFixture { ASSERT_EQUALS("[test.cpp:6:5]: (style) Label 'label' is not used. [unusedLabel]\n", errout_str()); } - #define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__) - // TODO: use options + // TODO: only used in a single place +#define checkCustomSettings(...) checkCustomSettings_(__FILE__, __LINE__, __VA_ARGS__) template - void checkCustomSettings_(const char* file, int line, const char (&code)[size], bool cpp = true, bool inconclusive = true, bool runSimpleChecks=true, bool verbose=false, Settings* settings = nullptr) { - if (!settings) { - settings = &_settings; - } - settings->certainty.setEnabled(Certainty::inconclusive, inconclusive); - settings->verbose = verbose; - + void checkCustomSettings_(const char* file, int line, const char (&code)[size], const Settings& settings) { // Tokenize.. - SimpleTokenizer tokenizer(*settings, *this, cpp); + SimpleTokenizer tokenizer(settings, *this); ASSERT_LOC(tokenizer.tokenize(code), file, line); // Check.. runChecks(tokenizer, this); - - (void)runSimpleChecks; // TODO Remove this - } - - template - void checkCustomSettings_(const char* file, int line, const char (&code)[size], Settings *s) { - checkCustomSettings_(file, line, code, true, true, true, false, s); } void testEvaluationOrder() { check("void f() {\n" " int x = dostuff();\n" " return x + x++;\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3:12]: (error) Expression 'x+x++' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); // #7226 check("long int f1(const char *exp) {\n" " return strtol(++exp, (char **)&exp, 10);\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("long int f1(const char *exp) {\n" " return dostuff(++exp, exp, 10);\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:2:23]: (error) Expression '++exp,exp' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); check("void f() {\n" " int a;\n" " while (a=x(), a==123) {}\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); // # 8717 @@ -11819,19 +11805,19 @@ class TestOther : public TestFixture { " char **local_argv = safe_malloc(sizeof (*local_argv));\n" " int local_argc = 0;\n" " local_argv[local_argc++] = argv[0];\n" - "}\n", false); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("void f() {\n" " int x = 0;\n" " return 0 + x++;\n" - "}\n", false); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("void f(int x, int y) {\n" " int a[10];\n" " a[x+y] = a[y+x]++;;\n" - "}\n", false); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3:10]: (error) Expression 'a[x+y]=a[y+x]++' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); check("void f(int i) {\n" @@ -11850,11 +11836,11 @@ class TestOther : public TestFixture { "}"); ASSERT_EQUALS("[test.cpp:2:22]: (error) Expression '~(-(++i))+i' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); - /*const*/ Settings settings11 = settingsBuilder(_settings).cpp(Standards::CPP11).build(); + const Settings settings11 = settingsBuilder(settings0).cpp(Standards::CPP11).certainty(Certainty::inconclusive).build(); checkCustomSettings("void f(int i) {\n" " i = i++ + 2;\n" - "}", &settings11); + "}", settings11); ASSERT_EQUALS("[test.cpp:2:11]: (error) Expression 'i+++2' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); } @@ -11862,7 +11848,7 @@ class TestOther : public TestFixture { // self assignment check("void f() {\n" " int x = x = y + 1;\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS( "[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n" "[test.c:2:9]: (style) Redundant assignment of 'x' to itself. [selfAssignment]\n", // duplicate @@ -11882,13 +11868,13 @@ class TestOther : public TestFixture { // FP check("void f(int id) {\n" " id = dostuff(id += 42);\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); // FN check("void f(int id) {\n" " id = id + dostuff(id += 42);\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); TODO_ASSERT_EQUALS("error", "", errout_str()); } @@ -11896,19 +11882,19 @@ class TestOther : public TestFixture { check("int f(void) {\n" " int t;\n" " return (unsigned char)(t=1,t^c);\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("void f(void) {\n" " int t;\n" " dostuff(t=1,t^c);\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:3:14]: (error) Expression 't=1,t^c' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); check("void f(void) {\n" " int t;\n" " dostuff((t=1,t),2);\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); // #8230 @@ -11916,28 +11902,28 @@ class TestOther : public TestFixture { " do\n" " ;\n" " while (++fp, (*fp) <= 0177);\n" - "}\n", false); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("void hprf(const char* fp) {\n" " do\n" " ;\n" " while (i++, ++fp, (*fp) <= 0177);\n" - "}\n", false); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); check("void f(const char* fp) {\n" " do\n" " ;\n" " while (f(++fp, (*fp) <= 7));\n" - "}\n", false); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:4:18]: (error) Expression '++fp,(*fp)<=7' depends on order of evaluation of side effects [unknownEvaluationOrder]\n", errout_str()); } void testEvaluationOrderSizeof() { check("void f(char *buf) {\n" " dostuff(buf++, sizeof(*buf));" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("", errout_str()); } @@ -11956,7 +11942,7 @@ class TestOther : public TestFixture { " if (0 > d.n) {\n" " return;\n" " }\n" - "}", false); + "}", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:8:11]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\n" "[test.c:12:9]: (style) Checking if unsigned expression 'd.n' is less than zero. [unsignedLessThanZero]\n", errout_str()); @@ -12362,7 +12348,7 @@ class TestOther : public TestFixture { "void Fred::func2(int c, int b, int a) { }\n" "void Fred::func3(int c, int b, int a) { }\n" "void Fred::func4(int c, int b, int a) { }\n", - true, false); + dinit(CheckOptions, $.inconclusive = false)); ASSERT_EQUALS("[test.cpp:3:16] -> [test.cpp:4:16]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\n" "[test.cpp:5:12] -> [test.cpp:6:16]: (warning) Function 'func3' argument order different: declaration ', b, c' definition 'c, b, a' [funcArgOrderDifferent]\n" "[test.cpp:9:20] -> [test.cpp:14:22]: (warning) Function 'func2' argument order different: declaration 'a, b, c' definition 'c, b, a' [funcArgOrderDifferent]\n" @@ -12466,7 +12452,7 @@ class TestOther : public TestFixture { "static int f(void) {\n" " int a;\n" " return 0;\n" - "}\n", false); + "}\n", dinit(CheckOptions, $.cpp = false)); ASSERT_EQUALS("[test.c:1:12] -> [test.c:4:9]: (style) Local variable 'a' shadows outer variable [shadowVariable]\n", errout_str()); check("int f() {\n" // #12591