Skip to content

Commit 680902c

Browse files
committed
removed usage of static Settings object from tests
1 parent 766a70e commit 680902c

File tree

4 files changed

+36
-40
lines changed

4 files changed

+36
-40
lines changed

test/testclass.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7419,24 +7419,21 @@ class TestClass : public TestFixture {
74197419

74207420

74217421
#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)
7422-
void checkVirtualFunctionCall_(const char* file, int line, const char code[], Settings *s = nullptr, bool inconclusive = true) {
7422+
void checkVirtualFunctionCall_(const char* file, int line, const char code[], bool inconclusive = true) {
74237423
// Clear the error log
74247424
errout.str("");
74257425

74267426
// Check..
7427-
if (!s) {
7428-
static Settings settings_;
7429-
s = &settings_;
7430-
s->severity.enable(Severity::warning);
7431-
}
7432-
s->certainty.setEnabled(Certainty::inconclusive, inconclusive);
7427+
Settings settings;
7428+
settings.severity.enable(Severity::warning);
7429+
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);
74337430

74347431
// Tokenize..
7435-
Tokenizer tokenizer(s, this);
7432+
Tokenizer tokenizer(&settings, this);
74367433
std::istringstream istr(code);
74377434
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);
74387435

7439-
CheckClass checkClass(&tokenizer, s, this);
7436+
CheckClass checkClass(&tokenizer, &settings, this);
74407437
checkClass.checkVirtualFunctionCallInConstructor();
74417438
}
74427439

test/testother.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class TestOther : public TestFixture {
358358
}
359359

360360
void checkInterlockedDecrement(const char code[]) {
361-
static Settings settings;
361+
Settings settings;
362362
settings.platformType = Settings::Win32A;
363363

364364
check(code, nullptr, false, false, true, false, &settings);
@@ -1542,7 +1542,7 @@ class TestOther : public TestFixture {
15421542
// Clear the error buffer..
15431543
errout.str("");
15441544

1545-
static Settings settings;
1545+
Settings settings;
15461546
settings.severity.enable(Severity::style);
15471547
settings.standards.cpp = Standards::CPP03; // #5560
15481548

test/testpreprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class TestPreprocessor : public TestFixture {
6464
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI(), &outputList);
6565

6666
if (errorLogger) {
67-
static Settings settings;
67+
Settings settings;
6868
Preprocessor p(settings, errorLogger);
6969
p.reportOutput(outputList, true);
7070
}

test/testtype.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,10 @@ class TestType : public TestFixture {
4444
}
4545

4646
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
47-
void check_(const char* file, int line, const char code[], Settings* settings = nullptr, const char filename[] = "test.cpp", const std::string& standard = "c++11") {
47+
void check_(const char* file, int line, const char code[], Settings* settings, const char filename[] = "test.cpp", const std::string& standard = "c++11") {
4848
// Clear the error buffer..
4949
errout.str("");
5050

51-
if (!settings) {
52-
static Settings _settings;
53-
settings = &_settings;
54-
}
5551
settings->severity.enable(Severity::warning);
5652
settings->severity.enable(Severity::portability);
5753
settings->standards.setCPP(standard);
@@ -66,6 +62,7 @@ class TestType : public TestFixture {
6662
}
6763

6864
void checkTooBigShift_Unix32() {
65+
Settings settings0;
6966
Settings settings;
7067
PLATFORM(settings, Settings::Unix32);
7168

@@ -166,7 +163,7 @@ class TestType : public TestFixture {
166163
// #7266: C++, shift in macro
167164
check("void f(unsigned int x) {\n"
168165
" UINFO(x << 1234);\n"
169-
"}");
166+
"}", &settings0);
170167
ASSERT_EQUALS("", errout.str());
171168

172169
// #8640
@@ -176,7 +173,7 @@ class TestType : public TestFixture {
176173
" constexpr const int shift[1] = {32};\n"
177174
" constexpr const int ret = a << shift[0];\n" // shift too many bits
178175
" return ret;\n"
179-
"}");
176+
"}", &settings0);
180177
ASSERT_EQUALS("[test.cpp:5]: (error) Shifting 32-bit value by 32 bits is undefined behaviour\n"
181178
"[test.cpp:5]: (error) Signed integer overflow for expression 'a<<shift[0]'.\n", errout.str());
182179

@@ -187,7 +184,7 @@ class TestType : public TestFixture {
187184
" if (k > 32)\n"
188185
" return 0;\n"
189186
" return rm>> k;\n"
190-
"}");
187+
"}", &settings0);
191188
ASSERT_EQUALS(
192189
"[test.cpp:4] -> [test.cpp:6]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 4.\n",
193190
errout.str());
@@ -199,7 +196,7 @@ class TestType : public TestFixture {
199196
" return 0;\n"
200197
" else\n"
201198
" return rm>> k;\n"
202-
"}");
199+
"}", &settings0);
203200
ASSERT_EQUALS(
204201
"[test.cpp:4] -> [test.cpp:7]: (warning) Shifting signed 32-bit value by 31 bits is undefined behaviour. See condition at line 4.\n",
205202
errout.str());
@@ -211,20 +208,20 @@ class TestType : public TestFixture {
211208
" return 0;\n"
212209
" else\n"
213210
" return rm>> k;\n"
214-
"}");
211+
"}", &settings0);
215212
ASSERT_EQUALS("", errout.str());
216213

217214
check("static long long f(int x, long long y) {\n"
218215
" if (x >= 64)\n"
219216
" return 0;\n"
220217
" return -(y << (x-1));\n"
221-
"}");
218+
"}", &settings0);
222219
ASSERT_EQUALS("", errout.str());
223220

224221
check("bool f() {\n"
225222
" std::ofstream outfile;\n"
226223
" outfile << vec_points[0](0) << static_cast<int>(d) << ' ';\n"
227-
"}");
224+
"}", &settings0);
228225
ASSERT_EQUALS("", errout.str());
229226

230227
check("void f(unsigned b, int len, unsigned char rem) {\n" // #10773
@@ -235,7 +232,7 @@ class TestType : public TestFixture {
235232
" if (bits == 512)\n"
236233
" len -= 8;\n"
237234
" }\n"
238-
"}\n");
235+
"}\n", &settings0);
239236
ASSERT_EQUALS("", errout.str());
240237
}
241238

@@ -282,12 +279,13 @@ class TestType : public TestFixture {
282279
}
283280

284281
void signConversion() {
282+
Settings settings0;
285283
Settings settings;
286284
PLATFORM(settings, Settings::Unix64);
287-
check("x = -4 * (unsigned)y;");
285+
check("x = -4 * (unsigned)y;", &settings0);
288286
ASSERT_EQUALS("[test.cpp:1]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", errout.str());
289287

290-
check("x = (unsigned)y * -4;");
288+
check("x = (unsigned)y * -4;", &settings0);
291289
ASSERT_EQUALS("[test.cpp:1]: (warning) Expression '-4' has a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", errout.str());
292290

293291
check("unsigned int dostuff(int x) {\n" // x is signed
@@ -299,35 +297,35 @@ class TestType : public TestFixture {
299297
check("unsigned int f1(signed int x, unsigned int y) {" // x is signed
300298
" return x * y;\n"
301299
"}\n"
302-
"void f2() { f1(-4,4); }");
300+
"void f2() { f1(-4,4); }", &settings0);
303301
ASSERT_EQUALS(
304302
"[test.cpp:1]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n",
305303
errout.str());
306304

307305
check("unsigned int f1(int x) {"
308306
" return x * 5U;\n"
309307
"}\n"
310-
"void f2() { f1(-4); }");
308+
"void f2() { f1(-4); }", &settings0);
311309
ASSERT_EQUALS(
312310
"[test.cpp:1]: (warning) Expression 'x' can have a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n",
313311
errout.str());
314312

315313
check("unsigned int f1(int x) {" // #6168: FP for inner calculation
316314
" return 5U * (1234 - x);\n" // <- signed subtraction, x is not sign converted
317315
"}\n"
318-
"void f2() { f1(-4); }");
316+
"void f2() { f1(-4); }", &settings0);
319317
ASSERT_EQUALS("", errout.str());
320318

321319
// Don't warn for + and -
322320
check("void f1(int x) {"
323321
" a = x + 5U;\n"
324322
"}\n"
325-
"void f2() { f1(-4); }");
323+
"void f2() { f1(-4); }", &settings0);
326324
ASSERT_EQUALS("", errout.str());
327325

328326
check("size_t foo(size_t x) {\n"
329327
" return -2 * x;\n"
330-
"}");
328+
"}", &settings0);
331329
ASSERT_EQUALS("[test.cpp:2]: (warning) Expression '-2' has a negative value. That is converted to an unsigned value and used in an unsigned calculation.\n", errout.str());
332330
}
333331

@@ -390,42 +388,43 @@ class TestType : public TestFixture {
390388
}
391389

392390
void checkFloatToIntegerOverflow() {
393-
check("x = (int)1E100;");
391+
Settings settings;
392+
check("x = (int)1E100;", &settings);
394393
ASSERT_EQUALS("[test.cpp:1]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
395394

396395
check("void f(void) {\n"
397396
" return (int)1E100;\n"
398-
"}");
397+
"}", &settings);
399398
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
400399

401400
check("void f(void) {\n"
402401
" return (int)-1E100;\n"
403-
"}");
402+
"}", &settings);
404403
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
405404

406405
check("void f(void) {\n"
407406
" return (short)1E6;\n"
408-
"}");
407+
"}", &settings);
409408
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
410409

411410
check("void f(void) {\n"
412411
" return (unsigned char)256.0;\n"
413-
"}");
412+
"}", &settings);
414413
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
415414

416415
check("void f(void) {\n"
417416
" return (unsigned char)255.5;\n"
418-
"}");
417+
"}", &settings);
419418
ASSERT_EQUALS("", removeFloat(errout.str()));
420419

421420
check("void f(void) {\n"
422421
" char c = 1234.5;\n"
423-
"}");
422+
"}", &settings);
424423
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
425424

426425
check("char f(void) {\n"
427426
" return 1234.5;\n"
428-
"}");
427+
"}", &settings);
429428
ASSERT_EQUALS("[test.cpp:2]: (error) Undefined behaviour: float () to integer conversion overflow.\n", removeFloat(errout.str()));
430429
}
431430
};

0 commit comments

Comments
 (0)