@@ -39,10 +39,14 @@ class TestCondition : public TestFixture {
3939 TestCondition () : TestFixture(" TestCondition" ) {}
4040
4141private:
42- const Settings settings0 = settingsBuilder().library(" qt.cfg" ).library(" std.cfg" ).severity(Severity::style).severity(Severity::warning).platform(cppcheck::Platform::Type::Native ).build();
43- Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).platform(cppcheck::Platform::Type::Native). build();
42+ Settings settings0 = settingsBuilder().library(" qt.cfg" ).library(" std.cfg" ).severity(Severity::style).severity(Severity::warning).build();
43+ Settings settings1 = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();
4444
4545 void run () override {
46+ // known platform..
47+ PLATFORM (settings0.platform , cppcheck::Platform::Type::Native);
48+ PLATFORM (settings1.platform , cppcheck::Platform::Type::Native);
49+
4650 const char cfg[] = " <?xml version=\" 1.0\" ?>\n "
4751 " <def>\n "
4852 " <function name=\" bar\" > <pure/> </function>\n "
@@ -128,7 +132,7 @@ class TestCondition : public TestFixture {
128132 TEST_CASE (knownConditionIncrementLoop); // #9808
129133 }
130134
131- void check (const char code[], Settings & settings, const char * filename = " test.cpp" ) {
135+ void check (const char code[], Settings * settings, const char * filename = " test.cpp" ) {
132136 // Clear the error buffer..
133137 errout.str (" " );
134138
@@ -142,21 +146,21 @@ class TestCondition : public TestFixture {
142146 std::map<std::string, simplecpp::TokenList*> filedata;
143147 simplecpp::preprocess (tokens2, tokens1, files, filedata, simplecpp::DUI ());
144148
145- Preprocessor preprocessor (settings);
149+ Preprocessor preprocessor (* settings);
146150 preprocessor.setDirectives (tokens1);
147151
148152 // Tokenizer..
149- Tokenizer tokenizer (& settings, this , &preprocessor);
153+ Tokenizer tokenizer (settings, this , &preprocessor);
150154 tokenizer.createTokens (std::move (tokens2));
151155 tokenizer.simplifyTokens1 (" " );
152156
153157 // Run checks..
154- runChecks<CheckCondition>(&tokenizer, & settings, this );
158+ runChecks<CheckCondition>(&tokenizer, settings, this );
155159 }
156160
157161 void check (const char code[], const char * filename = " test.cpp" , bool inconclusive = false ) {
158- Settings settings = settingsBuilder ( settings0) .certainty (Certainty::inconclusive, inconclusive). build ( );
159- check (code, settings , filename);
162+ settings0.certainty . setEnabled (Certainty::inconclusive, inconclusive);
163+ check (code, &settings0 , filename);
160164 }
161165
162166 void assignAndCompare () {
@@ -5631,69 +5635,70 @@ class TestCondition : public TestFixture {
56315635 }
56325636
56335637 void compareOutOfTypeRange () {
5634- Settings settingsUnix64 = settingsBuilder ().severity (Severity::style).platform (cppcheck::Platform::Type::Unix64).build ();
5638+ Settings settingsUnix64 = settingsBuilder ().severity (Severity::style).build ();
5639+ PLATFORM (settingsUnix64.platform , cppcheck::Platform::Type::Unix64);
56355640
56365641 check (" void f(unsigned char c) {\n "
56375642 " if (c == 256) {}\n "
5638- " }" , settingsUnix64);
5643+ " }" , & settingsUnix64);
56395644 ASSERT_EQUALS (" [test.cpp:2]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false.\n " , errout.str ());
56405645
56415646 check (" void f(unsigned char* b, int i) {\n " // #6372
56425647 " if (b[i] == 256) {}\n "
5643- " }" , settingsUnix64);
5648+ " }" , & settingsUnix64);
56445649 ASSERT_EQUALS (" [test.cpp:2]: (style) Comparing expression of type 'unsigned char' against value 256. Condition is always false.\n " , errout.str ());
56455650
56465651 check (" void f(unsigned char c) {\n "
56475652 " if (c == 255) {}\n "
5648- " }" , settingsUnix64);
5653+ " }" , & settingsUnix64);
56495654 ASSERT_EQUALS (" " , errout.str ());
56505655
56515656 check (" void f(bool b) {\n "
56525657 " if (b == true) {}\n "
5653- " }" , settingsUnix64);
5658+ " }" , & settingsUnix64);
56545659 ASSERT_EQUALS (" " , errout.str ());
56555660
56565661 // #10372
56575662 check (" void f(signed char x) {\n "
56585663 " if (x == 0xff) {}\n "
5659- " }" , settingsUnix64);
5664+ " }" , & settingsUnix64);
56605665 ASSERT_EQUALS (" [test.cpp:2]: (style) Comparing expression of type 'signed char' against value 255. Condition is always false.\n " , errout.str ());
56615666
56625667 check (" void f(short x) {\n "
56635668 " if (x == 0xffff) {}\n "
5664- " }" , settingsUnix64);
5669+ " }" , & settingsUnix64);
56655670 ASSERT_EQUALS (" [test.cpp:2]: (style) Comparing expression of type 'signed short' against value 65535. Condition is always false.\n " , errout.str ());
56665671
56675672 check (" void f(int x) {\n "
56685673 " if (x == 0xffffffff) {}\n "
5669- " }" , settingsUnix64);
5674+ " }" , & settingsUnix64);
56705675 ASSERT_EQUALS (" " , errout.str ());
56715676
56725677 check (" void f(long x) {\n "
56735678 " if (x == ~0L) {}\n "
5674- " }" , settingsUnix64);
5679+ " }" , & settingsUnix64);
56755680 ASSERT_EQUALS (" " , errout.str ());
56765681
56775682 check (" void f(long long x) {\n "
56785683 " if (x == ~0LL) {}\n "
5679- " }" , settingsUnix64);
5684+ " }" , & settingsUnix64);
56805685 ASSERT_EQUALS (" " , errout.str ());
56815686
56825687 check (" int f(int x) {\n "
56835688 " const int i = 0xFFFFFFFF;\n "
56845689 " if (x == i) {}\n "
5685- " }" , settingsUnix64);
5690+ " }" , & settingsUnix64);
56865691 ASSERT_EQUALS (" " , errout.str ());
56875692
56885693 check (" void f() {\n "
56895694 " char c;\n "
56905695 " if ((c = foo()) != -1) {}\n "
5691- " }" , settingsUnix64);
5696+ " }" , & settingsUnix64);
56925697 ASSERT_EQUALS (" " , errout.str ());
56935698
56945699 check (" void f(int x) {\n "
56955700 " if (x < 3000000000) {}\n "
5696- " }" , settingsUnix64);
5701+ " }" , & settingsUnix64);
56975702 ASSERT_EQUALS (" [test.cpp:2]: (style) Comparing expression of type 'signed int' against value 3000000000. Condition is always true.\n " , errout.str ());
56985703
56995704 check (" void f(const signed char i) {\n " // #8545
@@ -5703,7 +5708,7 @@ class TestCondition : public TestFixture {
57035708 " if (i < +128) {}\n " // warn
57045709 " if (i <= +127) {}\n " // warn
57055710 " if (i <= +126) {}\n "
5706- " }\n " , settingsUnix64);
5711+ " }\n " , & settingsUnix64);
57075712 ASSERT_EQUALS (" [test.cpp:2]: (style) Comparing expression of type 'const signed char' against value -129. Condition is always true.\n "
57085713 " [test.cpp:3]: (style) Comparing expression of type 'const signed char' against value -128. Condition is always true.\n "
57095714 " [test.cpp:5]: (style) Comparing expression of type 'const signed char' against value 128. Condition is always true.\n "
@@ -5727,7 +5732,7 @@ class TestCondition : public TestFixture {
57275732 " if (255 > u) {}\n "
57285733 " if (255 <= u) {}\n "
57295734 " if (255 >= u) {}\n " // warn
5730- " }\n " , settingsUnix64);
5735+ " }\n " , & settingsUnix64);
57315736 ASSERT_EQUALS (" [test.cpp:3]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always false.\n "
57325737 " [test.cpp:4]: (style) Comparing expression of type 'const unsigned char' against value 0. Condition is always true.\n "
57335738 " [test.cpp:6]: (style) Comparing expression of type 'const unsigned char' against value 255. Condition is always false.\n "
0 commit comments