@@ -50,7 +50,8 @@ class TestAstUtils : public TestFixture {
5050 }
5151
5252#define findLambdaEndToken (...) findLambdaEndToken_(__FILE__, __LINE__, __VA_ARGS__)
53- bool findLambdaEndToken_ (const char * file, int line, const char code[], const char pattern[] = nullptr , bool checkNext = true ) {
53+ template <size_t size>
54+ bool findLambdaEndToken_ (const char * file, int line, const char (&code)[size], const char pattern[] = nullptr, bool checkNext = true) {
5455 const Settings settings;
5556 SimpleTokenizer tokenizer (settings, *this );
5657 ASSERT_LOC (tokenizer.tokenize (code), file, line);
@@ -88,7 +89,8 @@ class TestAstUtils : public TestFixture {
8889 }
8990
9091#define findLambdaStartToken (code ) findLambdaStartToken_(code, __FILE__, __LINE__)
91- bool findLambdaStartToken_ (const char code[], const char * file, int line) {
92+ template <size_t size>
93+ bool findLambdaStartToken_ (const char (&code)[size], const char* file, int line) {
9294 SimpleTokenizer tokenizer (settingsDefault, *this );
9395 ASSERT_LOC (tokenizer.tokenize (code), file, line);
9496 const Token * const tokStart = (::findLambdaStartToken)(tokenizer.list .back ());
@@ -119,7 +121,8 @@ class TestAstUtils : public TestFixture {
119121 }
120122
121123#define isNullOperand (code ) isNullOperand_(code, __FILE__, __LINE__)
122- bool isNullOperand_ (const char code[], const char * file, int line) {
124+ template <size_t size>
125+ bool isNullOperand_ (const char (&code)[size], const char* file, int line) {
123126 SimpleTokenizer tokenizer (settingsDefault, *this );
124127 ASSERT_LOC (tokenizer.tokenize (code), file, line);
125128 return (::isNullOperand)(tokenizer.tokens ());
@@ -139,7 +142,8 @@ class TestAstUtils : public TestFixture {
139142 }
140143
141144#define isReturnScope (code, offset ) isReturnScope_(code, offset, __FILE__, __LINE__)
142- bool isReturnScope_ (const char code[], int offset, const char * file, int line) {
145+ template <size_t size>
146+ bool isReturnScope_ (const char (&code)[size], int offset, const char* file, int line) {
143147 SimpleTokenizer tokenizer (settingsDefault, *this );
144148 ASSERT_LOC (tokenizer.tokenize (code), file, line);
145149 const Token * const tok = (offset < 0 )
@@ -168,7 +172,8 @@ class TestAstUtils : public TestFixture {
168172 }
169173
170174#define isSameExpression (...) isSameExpression_(__FILE__, __LINE__, __VA_ARGS__)
171- bool isSameExpression_ (const char * file, int line, const char code[], const char tokStr1[], const char tokStr2[], bool cpp) {
175+ template <size_t size>
176+ bool isSameExpression_ (const char * file, int line, const char (&code)[size], const char tokStr1[], const char tokStr2[], bool cpp) {
172177 SimpleTokenizer tokenizer (settingsDefault, *this );
173178 ASSERT_LOC (tokenizer.tokenize (code, cpp), file, line);
174179 const Token * const tok1 = Token::findsimplematch (tokenizer.tokens (), tokStr1, strlen (tokStr1));
@@ -215,7 +220,8 @@ class TestAstUtils : public TestFixture {
215220 }
216221
217222#define isVariableChanged (code, startPattern, endPattern ) isVariableChanged_(code, startPattern, endPattern, __FILE__, __LINE__)
218- bool isVariableChanged_ (const char code[], const char startPattern[], const char endPattern[], const char * file, int line) {
223+ template <size_t size>
224+ bool isVariableChanged_ (const char (&code)[size], const char startPattern[], const char endPattern[], const char* file, int line) {
219225 SimpleTokenizer tokenizer (settingsDefault, *this );
220226 ASSERT_LOC (tokenizer.tokenize (code), file, line);
221227 const Token * const tok1 = Token::findsimplematch (tokenizer.tokens (), startPattern, strlen (startPattern));
@@ -248,7 +254,8 @@ class TestAstUtils : public TestFixture {
248254 }
249255
250256#define isVariableChangedByFunctionCall (code, pattern, inconclusive ) isVariableChangedByFunctionCall_(code, pattern, inconclusive, __FILE__, __LINE__)
251- bool isVariableChangedByFunctionCall_ (const char code[], const char pattern[], bool *inconclusive, const char * file, int line) {
257+ template <size_t size>
258+ bool isVariableChangedByFunctionCall_ (const char (&code)[size], const char pattern[], bool *inconclusive, const char* file, int line) {
252259 SimpleTokenizer tokenizer (settingsDefault, *this );
253260 ASSERT_LOC (tokenizer.tokenize (code), file, line);
254261 const Token * const argtok = Token::findmatch (tokenizer.tokens (), pattern);
@@ -258,126 +265,125 @@ class TestAstUtils : public TestFixture {
258265 }
259266
260267 void isVariableChangedByFunctionCallTest () {
261- const char *code;
262268 bool inconclusive;
263269
264270 // #8271 - template method
265- code = " void f(int x) {\n "
266- " a<int>(x);\n "
267- " }" ;
271+ const char code1[] = " void f(int x) {\n "
272+ " a<int>(x);\n "
273+ " }" ;
268274 inconclusive = false ;
269- ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code , " x ) ;" , &inconclusive));
275+ ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code1 , " x ) ;" , &inconclusive));
270276 ASSERT_EQUALS (true , inconclusive);
271277
272- code = " int f(int x) {\n "
273- " return int(x);\n "
274- " }\n " ;
278+ const char code2[] = " int f(int x) {\n "
279+ " return int(x);\n "
280+ " }\n " ;
275281 inconclusive = false ;
276- ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code , " x ) ;" , &inconclusive));
282+ ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code2 , " x ) ;" , &inconclusive));
277283 ASSERT_EQUALS (false , inconclusive);
278284
279- code = " void g(int* p);\n "
280- " void f(int x) {\n "
281- " return g(&x);\n "
282- " }\n " ;
285+ const char code3[] = " void g(int* p);\n "
286+ " void f(int x) {\n "
287+ " return g(&x);\n "
288+ " }\n " ;
283289 inconclusive = false ;
284- ASSERT_EQUALS (true , isVariableChangedByFunctionCall (code , " x ) ;" , &inconclusive));
290+ ASSERT_EQUALS (true , isVariableChangedByFunctionCall (code3 , " x ) ;" , &inconclusive));
285291 ASSERT_EQUALS (false , inconclusive);
286292
287- code = " void g(const int* p);\n "
288- " void f(int x) {\n "
289- " return g(&x);\n "
290- " }\n " ;
293+ const char code4[] = " void g(const int* p);\n "
294+ " void f(int x) {\n "
295+ " return g(&x);\n "
296+ " }\n " ;
291297 inconclusive = false ;
292- ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code , " x ) ;" , &inconclusive));
298+ ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code4 , " x ) ;" , &inconclusive));
293299 ASSERT_EQUALS (false , inconclusive);
294300
295- code = " void g(int** pp);\n "
296- " void f(int* p) {\n "
297- " return g(&p);\n "
298- " }\n " ;
301+ const char code5[] = " void g(int** pp);\n "
302+ " void f(int* p) {\n "
303+ " return g(&p);\n "
304+ " }\n " ;
299305 inconclusive = false ;
300- ASSERT_EQUALS (true , isVariableChangedByFunctionCall (code , " p ) ;" , &inconclusive));
306+ ASSERT_EQUALS (true , isVariableChangedByFunctionCall (code5 , " p ) ;" , &inconclusive));
301307 ASSERT_EQUALS (false , inconclusive);
302308
303- code = " void g(int* const* pp);\n "
304- " void f(int* p) {\n "
305- " return g(&p);\n "
306- " }\n " ;
309+ const char code6[] = " void g(int* const* pp);\n "
310+ " void f(int* p) {\n "
311+ " return g(&p);\n "
312+ " }\n " ;
307313 inconclusive = false ;
308- ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code , " p ) ;" , &inconclusive));
314+ ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code6 , " p ) ;" , &inconclusive));
309315 ASSERT_EQUALS (false , inconclusive);
310316
311- code = " void g(int a[2]);\n "
312- " void f() {\n "
313- " int b[2] = {};\n "
314- " return g(b);\n "
315- " }\n " ;
317+ const char code7[] = " void g(int a[2]);\n "
318+ " void f() {\n "
319+ " int b[2] = {};\n "
320+ " return g(b);\n "
321+ " }\n " ;
316322 inconclusive = false ;
317- ASSERT_EQUALS (true , isVariableChangedByFunctionCall (code , " b ) ;" , &inconclusive));
323+ ASSERT_EQUALS (true , isVariableChangedByFunctionCall (code7 , " b ) ;" , &inconclusive));
318324 ASSERT_EQUALS (false , inconclusive);
319325
320- code = " void g(const int a[2]);\n "
321- " void f() {\n "
322- " int b[2] = {};\n "
323- " return g(b);\n "
324- " }\n " ;
326+ const char code8[] = " void g(const int a[2]);\n "
327+ " void f() {\n "
328+ " int b[2] = {};\n "
329+ " return g(b);\n "
330+ " }\n " ;
325331 inconclusive = false ;
326- TODO_ASSERT_EQUALS (false , true , isVariableChangedByFunctionCall (code , " b ) ;" , &inconclusive));
332+ TODO_ASSERT_EQUALS (false , true , isVariableChangedByFunctionCall (code8 , " b ) ;" , &inconclusive));
327333 ASSERT_EQUALS (false , inconclusive);
328334
329- code = " void g(std::array<int, 2> a);\n "
330- " void f() {\n "
331- " std::array<int, 2> b = {};\n "
332- " return g(b);\n "
333- " }\n " ;
335+ const char code9[] = " void g(std::array<int, 2> a);\n "
336+ " void f() {\n "
337+ " std::array<int, 2> b = {};\n "
338+ " return g(b);\n "
339+ " }\n " ;
334340 inconclusive = false ;
335- ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code , " b ) ;" , &inconclusive));
341+ ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code9 , " b ) ;" , &inconclusive));
336342 ASSERT_EQUALS (false , inconclusive);
337343
338- code = " void g(std::array<int, 2>& a);\n "
339- " void f() {\n "
340- " std::array<int, 2> b = {};\n "
341- " return g(b);\n "
342- " }\n " ;
344+ const char code10[] = " void g(std::array<int, 2>& a);\n "
345+ " void f() {\n "
346+ " std::array<int, 2> b = {};\n "
347+ " return g(b);\n "
348+ " }\n " ;
343349 inconclusive = false ;
344- ASSERT_EQUALS (true , isVariableChangedByFunctionCall (code , " b ) ;" , &inconclusive));
350+ ASSERT_EQUALS (true , isVariableChangedByFunctionCall (code10 , " b ) ;" , &inconclusive));
345351 ASSERT_EQUALS (false , inconclusive);
346352
347- code = " void g(const std::array<int, 2>& a);\n "
348- " void f() {\n "
349- " std::array<int, 2> b = {};\n "
350- " return g(b);\n "
351- " }\n " ;
353+ const char code11[] = " void g(const std::array<int, 2>& a);\n "
354+ " void f() {\n "
355+ " std::array<int, 2> b = {};\n "
356+ " return g(b);\n "
357+ " }\n " ;
352358 inconclusive = false ;
353- ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code , " b ) ;" , &inconclusive));
359+ ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code11 , " b ) ;" , &inconclusive));
354360 ASSERT_EQUALS (false , inconclusive);
355361
356- code = " void g(std::array<int, 2>* p);\n "
357- " void f() {\n "
358- " std::array<int, 2> b = {};\n "
359- " return g(&b);\n "
360- " }\n " ;
362+ const char code12[] = " void g(std::array<int, 2>* p);\n "
363+ " void f() {\n "
364+ " std::array<int, 2> b = {};\n "
365+ " return g(&b);\n "
366+ " }\n " ;
361367 inconclusive = false ;
362- ASSERT_EQUALS (true , isVariableChangedByFunctionCall (code , " b ) ;" , &inconclusive));
368+ ASSERT_EQUALS (true , isVariableChangedByFunctionCall (code12 , " b ) ;" , &inconclusive));
363369 ASSERT_EQUALS (false , inconclusive);
364370
365- code = " struct S {};\n "
366- " void g(S);\n "
367- " void f(S* s) {\n "
368- " g(*s);\n "
369- " }\n " ;
371+ const char code13[] = " struct S {};\n "
372+ " void g(S);\n "
373+ " void f(S* s) {\n "
374+ " g(*s);\n "
375+ " }\n " ;
370376 inconclusive = false ;
371- ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code , " s ) ;" , &inconclusive));
377+ ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code13 , " s ) ;" , &inconclusive));
372378 ASSERT_EQUALS (false , inconclusive);
373379
374- code = " struct S {};\n "
375- " void g(const S&);\n "
376- " void f(S* s) {\n "
377- " g(*s);\n "
378- " }\n " ;
380+ const char code14[] = " struct S {};\n "
381+ " void g(const S&);\n "
382+ " void f(S* s) {\n "
383+ " g(*s);\n "
384+ " }\n " ;
379385 inconclusive = false ;
380- ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code , " s ) ;" , &inconclusive));
386+ ASSERT_EQUALS (false , isVariableChangedByFunctionCall (code14 , " s ) ;" , &inconclusive));
381387 ASSERT_EQUALS (false , inconclusive);
382388 }
383389
0 commit comments