Skip to content

Commit f37d352

Browse files
committed
s
1 parent 241098b commit f37d352

20 files changed

+483
-427
lines changed

test/helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class SimpleTokenizer : public Tokenizer {
6767

6868
/**
6969
* Tokenize code
70-
* @param data The code
70+
* @param code The code
7171
* @param cpp Indicates if the code is C++
7272
* @param configuration E.g. "A" for code where "#ifdef A" is true
7373
* @return false if source code contains syntax errors

test/testclass.cpp

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "tokenlist.h"
2727

2828
#include <list>
29-
#include <sstream>
3029
#include <string>
3130
#include <vector>
3231

@@ -249,7 +248,7 @@ class TestClass : public TestFixture {
249248

250249
#define checkCopyCtorAndEqOperator(code) checkCopyCtorAndEqOperator_(code, __FILE__, __LINE__)
251250
template<size_t size>
252-
void checkCopyCtorAndEqOperator_(const char code[], const char* file, int line) {
251+
void checkCopyCtorAndEqOperator_(const char (&code)[size], const char* file, int line) {
253252
const Settings settings = settingsBuilder().severity(Severity::warning).build();
254253

255254
// Tokenize..
@@ -351,7 +350,8 @@ class TestClass : public TestFixture {
351350
}
352351

353352
#define checkExplicitConstructors(code) checkExplicitConstructors_(code, __FILE__, __LINE__)
354-
void checkExplicitConstructors_(const char code[], const char* file, int line) {
353+
template<size_t size>
354+
void checkExplicitConstructors_(const char (&code)[size], const char* file, int line) {
355355
// Tokenize..
356356
SimpleTokenizer tokenizer(settings0, *this);
357357
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -499,7 +499,8 @@ class TestClass : public TestFixture {
499499
}
500500

501501
#define checkDuplInheritedMembers(code) checkDuplInheritedMembers_(code, __FILE__, __LINE__)
502-
void checkDuplInheritedMembers_(const char code[], const char* file, int line) {
502+
template<size_t size>
503+
void checkDuplInheritedMembers_(const char (&code)[size], const char* file, int line) {
503504
// Tokenize..
504505
SimpleTokenizer tokenizer(settings1, *this);
505506
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -715,7 +716,8 @@ class TestClass : public TestFixture {
715716
}
716717

717718
#define checkCopyConstructor(code) checkCopyConstructor_(code, __FILE__, __LINE__)
718-
void checkCopyConstructor_(const char code[], const char* file, int line) {
719+
template<size_t size>
720+
void checkCopyConstructor_(const char (&code)[size], const char* file, int line) {
719721
// Tokenize..
720722
SimpleTokenizer tokenizer(settings3, *this);
721723
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -1158,7 +1160,8 @@ class TestClass : public TestFixture {
11581160

11591161
// Check that operator Equal returns reference to this
11601162
#define checkOpertorEqRetRefThis(code) checkOpertorEqRetRefThis_(code, __FILE__, __LINE__)
1161-
void checkOpertorEqRetRefThis_(const char code[], const char* file, int line) {
1163+
template<size_t size>
1164+
void checkOpertorEqRetRefThis_(const char (&code)[size], const char* file, int line) {
11621165
// Tokenize..
11631166
SimpleTokenizer tokenizer(settings0, *this);
11641167
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -1628,7 +1631,8 @@ class TestClass : public TestFixture {
16281631

16291632
// Check that operator Equal checks for assignment to self
16301633
#define checkOpertorEqToSelf(code) checkOpertorEqToSelf_(code, __FILE__, __LINE__)
1631-
void checkOpertorEqToSelf_(const char code[], const char* file, int line) {
1634+
template<size_t size>
1635+
void checkOpertorEqToSelf_(const char (&code)[size], const char* file, int line) {
16321636
// Tokenize..
16331637
SimpleTokenizer tokenizer(settings1, *this);
16341638
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -2583,7 +2587,8 @@ class TestClass : public TestFixture {
25832587

25842588
// Check that base classes have virtual destructors
25852589
#define checkVirtualDestructor(...) checkVirtualDestructor_(__FILE__, __LINE__, __VA_ARGS__)
2586-
void checkVirtualDestructor_(const char* file, int line, const char code[], bool inconclusive = false) {
2590+
template<size_t size>
2591+
void checkVirtualDestructor_(const char* file, int line, const char (&code)[size], bool inconclusive = false) {
25872592
const Settings s = settingsBuilder(settings0).certainty(Certainty::inconclusive, inconclusive).severity(Severity::warning).build();
25882593

25892594
// Tokenize..
@@ -2916,12 +2921,14 @@ class TestClass : public TestFixture {
29162921

29172922

29182923
#define checkNoMemset(...) checkNoMemset_(__FILE__, __LINE__, __VA_ARGS__)
2919-
void checkNoMemset_(const char* file, int line, const char code[]) {
2924+
template<size_t size>
2925+
void checkNoMemset_(const char* file, int line, const char (&code)[size]) {
29202926
const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::portability).library("std.cfg").library("posix.cfg").build();
29212927
checkNoMemset_(file, line, code, settings);
29222928
}
29232929

2924-
void checkNoMemset_(const char* file, int line, const char code[], const Settings &settings) {
2930+
template<size_t size>
2931+
void checkNoMemset_(const char* file, int line, const char (&code)[size], const Settings &settings) {
29252932
// Tokenize..
29262933
SimpleTokenizer tokenizer(settings, *this);
29272934
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -3566,7 +3573,8 @@ class TestClass : public TestFixture {
35663573
}
35673574

35683575
#define checkThisSubtraction(code) checkThisSubtraction_(code, __FILE__, __LINE__)
3569-
void checkThisSubtraction_(const char code[], const char* file, int line) {
3576+
template<size_t size>
3577+
void checkThisSubtraction_(const char (&code)[size], const char* file, int line) {
35703578
// Tokenize..
35713579
SimpleTokenizer tokenizer(settings1, *this);
35723580
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -3595,7 +3603,8 @@ class TestClass : public TestFixture {
35953603
}
35963604

35973605
#define checkConst(...) checkConst_(__FILE__, __LINE__, __VA_ARGS__)
3598-
void checkConst_(const char* file, int line, const char code[], const Settings *s = nullptr, bool inconclusive = true) {
3606+
template<size_t size>
3607+
void checkConst_(const char* file, int line, const char (&code)[size], const Settings *s = nullptr, bool inconclusive = true) {
35993608
const Settings settings = settingsBuilder(s ? *s : settings0).certainty(Certainty::inconclusive, inconclusive).build();
36003609

36013610
// Tokenize..
@@ -7515,7 +7524,8 @@ class TestClass : public TestFixture {
75157524
}
75167525

75177526
#define checkInitializerListOrder(code) checkInitializerListOrder_(code, __FILE__, __LINE__)
7518-
void checkInitializerListOrder_(const char code[], const char* file, int line) {
7527+
template<size_t size>
7528+
void checkInitializerListOrder_(const char (&code)[size], const char* file, int line) {
75197529
// Tokenize..
75207530
SimpleTokenizer tokenizer(settings2, *this);
75217531
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -7649,7 +7659,8 @@ class TestClass : public TestFixture {
76497659
}
76507660

76517661
#define checkInitializationListUsage(code) checkInitializationListUsage_(code, __FILE__, __LINE__)
7652-
void checkInitializationListUsage_(const char code[], const char* file, int line) {
7662+
template<size_t size>
7663+
void checkInitializationListUsage_(const char (&code)[size], const char* file, int line) {
76537664
// Check..
76547665
const Settings settings = settingsBuilder().severity(Severity::performance).build();
76557666

@@ -7860,7 +7871,8 @@ class TestClass : public TestFixture {
78607871

78617872

78627873
#define checkSelfInitialization(code) checkSelfInitialization_(code, __FILE__, __LINE__)
7863-
void checkSelfInitialization_(const char code[], const char* file, int line) {
7874+
template<size_t size>
7875+
void checkSelfInitialization_(const char (&code)[size], const char* file, int line) {
78647876
// Tokenize..
78657877
SimpleTokenizer tokenizer(settings0, *this);
78667878
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -7967,7 +7979,8 @@ class TestClass : public TestFixture {
79677979

79687980

79697981
#define checkVirtualFunctionCall(...) checkVirtualFunctionCall_(__FILE__, __LINE__, __VA_ARGS__)
7970-
void checkVirtualFunctionCall_(const char* file, int line, const char code[], bool inconclusive = true) {
7982+
template<size_t size>
7983+
void checkVirtualFunctionCall_(const char* file, int line, const char (&code)[size], bool inconclusive = true) {
79717984
// Check..
79727985
const Settings settings = settingsBuilder().severity(Severity::warning).severity(Severity::style).certainty(Certainty::inconclusive, inconclusive).build();
79737986

@@ -8311,7 +8324,8 @@ class TestClass : public TestFixture {
83118324

83128325

83138326
#define checkOverride(code) checkOverride_(code, __FILE__, __LINE__)
8314-
void checkOverride_(const char code[], const char* file, int line) {
8327+
template<size_t size>
8328+
void checkOverride_(const char (&code)[size], const char* file, int line) {
83158329
const Settings settings = settingsBuilder().severity(Severity::style).build();
83168330

83178331
// Tokenize..
@@ -8692,7 +8706,8 @@ class TestClass : public TestFixture {
86928706
}
86938707

86948708
#define checkUnsafeClassRefMember(code) checkUnsafeClassRefMember_(code, __FILE__, __LINE__)
8695-
void checkUnsafeClassRefMember_(const char code[], const char* file, int line) {
8709+
template<size_t size>
8710+
void checkUnsafeClassRefMember_(const char (&code)[size], const char* file, int line) {
86968711
/*const*/ Settings settings = settingsBuilder().severity(Severity::warning).build();
86978712
settings.safeChecks.classes = true;
86988713

@@ -8712,7 +8727,8 @@ class TestClass : public TestFixture {
87128727

87138728

87148729
#define checkThisUseAfterFree(code) checkThisUseAfterFree_(code, __FILE__, __LINE__)
8715-
void checkThisUseAfterFree_(const char code[], const char* file, int line) {
8730+
template<size_t size>
8731+
void checkThisUseAfterFree_(const char (&code)[size], const char* file, int line) {
87168732
// Tokenize..
87178733
SimpleTokenizer tokenizer(settings1, *this);
87188734
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -8910,7 +8926,8 @@ class TestClass : public TestFixture {
89108926

89118927

89128928
#define getFileInfo(code) getFileInfo_(code, __FILE__, __LINE__)
8913-
void getFileInfo_(const char code[], const char* file, int line) {
8929+
template<size_t size>
8930+
void getFileInfo_(const char (&code)[size], const char* file, int line) {
89148931
// Tokenize..
89158932
SimpleTokenizer tokenizer(settings1, *this);
89168933
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -8928,7 +8945,8 @@ class TestClass : public TestFixture {
89288945
}
89298946

89308947
#define checkReturnByReference(...) checkReturnByReference_(__FILE__, __LINE__, __VA_ARGS__)
8931-
void checkReturnByReference_(const char* file, int line, const char code[]) {
8948+
template<size_t size>
8949+
void checkReturnByReference_(const char* file, int line, const char (&code)[size]) {
89328950
const Settings settings = settingsBuilder().severity(Severity::performance).library("std.cfg").build();
89338951

89348952
std::vector<std::string> files(1, "test.cpp");

test/testcondition.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,8 @@ class TestCondition : public TestFixture {
538538
ASSERT_EQUALS("", errout_str());
539539
}
540540

541-
void checkPureFunction_(const char code[], const char* file, int line) {
541+
template<size_t size>
542+
void checkPureFunction_(const char (&code)[size], const char* file, int line) {
542543
// Tokenize..
543544
SimpleTokenizer tokenizer(settings1, *this);
544545
ASSERT_LOC(tokenizer.tokenize(code), file, line);

test/testconstructors.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class TestConstructors : public TestFixture {
3131
const Settings settings = settingsBuilder().severity(Severity::style).severity(Severity::warning).build();
3232

3333
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
34-
void check_(const char* file, int line, const char code[], bool inconclusive = false) {
34+
template<size_t size>
35+
void check_(const char* file, int line, const char (&code)[size], bool inconclusive = false) {
3536
const Settings settings1 = settingsBuilder(settings).certainty(Certainty::inconclusive, inconclusive).build();
3637

3738
// Tokenize..
@@ -43,7 +44,8 @@ class TestConstructors : public TestFixture {
4344
checkClass.constructors();
4445
}
4546

46-
void check_(const char* file, int line, const char code[], const Settings &s) {
47+
template<size_t size>
48+
void check_(const char* file, int line, const char (&code)[size], const Settings &s) {
4749
// Tokenize..
4850
SimpleTokenizer tokenizer(s, *this);
4951
ASSERT_LOC(tokenizer.tokenize(code), file, line);

test/testexceptionsafety.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class TestExceptionSafety : public TestFixture {
5656
}
5757

5858
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
59-
void check_(const char* file, int line, const char code[], bool inconclusive = false, const Settings *s = nullptr) {
59+
template<size_t size>
60+
void check_(const char* file, int line, const char (&code)[size], bool inconclusive = false, const Settings *s = nullptr) {
6061
const Settings settings1 = settingsBuilder(s ? *s : settings).certainty(Certainty::inconclusive, inconclusive).build();
6162

6263
// Tokenize..

test/testfunctions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ class TestFunctions : public TestFixture {
104104
}
105105

106106
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
107-
void check_(const char* file, int line, const char code[], bool cpp = true, const Settings* settings_ = nullptr) {
107+
template<size_t size>
108+
void check_(const char* file, int line, const char (&code)[size], bool cpp = true, const Settings* settings_ = nullptr) {
108109
if (!settings_)
109110
settings_ = &settings;
110111

test/testgarbage.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ class TestGarbage : public TestFixture {
271271
}
272272

273273
#define checkCodeInternal(code, filename) checkCodeInternal_(code, filename, __FILE__, __LINE__)
274-
std::string checkCode(const char code[], bool cpp = true) {
274+
template<size_t size>
275+
std::string checkCode(const char (&code)[size], bool cpp = true) {
275276
// double the tests - run each example as C as well as C++
276277

277278
// run alternate check first. It should only ensure stability - so we catch exceptions here.
@@ -282,7 +283,8 @@ class TestGarbage : public TestFixture {
282283
return checkCodeInternal(code, cpp);
283284
}
284285

285-
std::string checkCodeInternal_(const char code[], bool cpp, const char* file, int line) {
286+
template<size_t size>
287+
std::string checkCodeInternal_(const char (&code)[size], bool cpp, const char* file, int line) {
286288
// tokenize..
287289
SimpleTokenizer tokenizer(settings, *this);
288290
ASSERT_LOC(tokenizer.tokenize(code, cpp), file, line);
@@ -296,7 +298,8 @@ class TestGarbage : public TestFixture {
296298
}
297299

298300
#define getSyntaxError(code) getSyntaxError_(code, __FILE__, __LINE__)
299-
std::string getSyntaxError_(const char code[], const char* file, int line) {
301+
template<size_t size>
302+
std::string getSyntaxError_(const char (&code)[size], const char* file, int line) {
300303
SimpleTokenizer tokenizer(settings, *this);
301304
try {
302305
ASSERT_LOC(tokenizer.tokenize(code), file, line);
@@ -1241,9 +1244,9 @@ class TestGarbage : public TestFixture {
12411244
}
12421245

12431246
void garbageCode152() { // happened in travis, originally from llvm clang code
1244-
const char* code = "template <bool foo = std::value &&>\n"
1245-
"static std::string foo(char *Bla) {\n"
1246-
" while (Bla[1] && Bla[1] != ',') }\n";
1247+
const char code[] = "template <bool foo = std::value &&>\n"
1248+
"static std::string foo(char *Bla) {\n"
1249+
" while (Bla[1] && Bla[1] != ',') }\n";
12471250
checkCode(code);
12481251
ignore_errout(); // we are not interested in the output
12491252
}
@@ -1291,18 +1294,18 @@ class TestGarbage : public TestFixture {
12911294

12921295
void garbageValueFlow() {
12931296
// #6089
1294-
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
1295-
"{\n"
1296-
" (foo(s, , 2, , , 5, , 7)) abort()\n"
1297-
"}\n";
1298-
ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX);
1297+
const char code1[] = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"
1298+
"{\n"
1299+
" (foo(s, , 2, , , 5, , 7)) abort()\n"
1300+
"}\n";
1301+
ASSERT_THROW_INTERNAL(checkCode(code1), SYNTAX);
12991302

13001303
// 6122 survive garbage code
1301-
code = "; { int i ; for ( i = 0 ; = 123 ; ) - ; }";
1302-
ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX);
1304+
const char code2[] = "; { int i ; for ( i = 0 ; = 123 ; ) - ; }";
1305+
ASSERT_THROW_INTERNAL(checkCode(code2), SYNTAX);
13031306

1304-
code = "void f1() { for (int n = 0 n < 10 n++); }";
1305-
ASSERT_THROW_INTERNAL(checkCode(code), SYNTAX);
1307+
const char code3[] = "void f1() { for (int n = 0 n < 10 n++); }";
1308+
ASSERT_THROW_INTERNAL(checkCode(code3), SYNTAX);
13061309
}
13071310

13081311
void garbageSymbolDatabase() {

test/testinternal.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class TestInternal : public TestFixture {
4747
}
4848

4949
#define check(code) check_(code, __FILE__, __LINE__)
50-
void check_(const char code[], const char* file, int line) {
50+
template<size_t size>
51+
void check_(const char (&code)[size], const char* file, int line) {
5152
// Tokenize..
5253
SimpleTokenizer tokenizer(settings, *this);
5354
ASSERT_LOC(tokenizer.tokenize(code), file, line);

0 commit comments

Comments
 (0)