@@ -64,12 +64,12 @@ class TestString : public TestFixture {
6464 struct CheckOptions
6565 {
6666 CheckOptions () = default ;
67- const char * filename = " test.cpp " ;
67+ bool cpp = true ;
6868 };
6969
7070#define check (...) check_(__FILE__, __LINE__, __VA_ARGS__)
7171 void check_ (const char * file, int line, const char code[], const CheckOptions& options = make_default_obj()) {
72- std::vector<std::string> files (1 , options.filename );
72+ std::vector<std::string> files (1 , options.cpp ? " test.cpp " : " test.c " );
7373 Tokenizer tokenizer (settings, *this );
7474 PreprocessorHelper::preprocess (code, files, tokenizer, *this );
7575
@@ -337,7 +337,7 @@ class TestString : public TestFixture {
337337
338338 check (" bool foo(char* c) {\n "
339339 " return \" x\" == c+foo;\n "
340- " }" , dinit (CheckOptions, $.filename = " test.c " ));
340+ " }" , dinit (CheckOptions, $.cpp = false ));
341341 ASSERT_EQUALS (" [test.c:2]: (warning) String literal compared with variable 'c+foo'. Did you intend to use strcmp() instead?\n " , errout_str ());
342342
343343 check (" bool foo(Foo c) {\n "
@@ -347,7 +347,7 @@ class TestString : public TestFixture {
347347
348348 check (" bool foo(Foo c) {\n "
349349 " return \" x\" == c.foo;\n "
350- " }" , dinit (CheckOptions, $.filename = " test.c " ));
350+ " }" , dinit (CheckOptions, $.cpp = false ));
351351 ASSERT_EQUALS (" [test.c:2]: (warning) String literal compared with variable 'c.foo'. Did you intend to use strcmp() instead?\n " , errout_str ());
352352
353353 check (" bool foo(const std::string& c) {\n "
@@ -363,7 +363,7 @@ class TestString : public TestFixture {
363363 // Ticket #4257
364364 check (" bool foo() {\n "
365365 " MyString *str=Getter();\n "
366- " return *str==\" bug\" ; }\n " , dinit (CheckOptions, $.filename = " test.c " ));
366+ " return *str==\" bug\" ; }\n " , dinit (CheckOptions, $.cpp = false ));
367367 ASSERT_EQUALS (" [test.c:3]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead?\n " , errout_str ());
368368
369369 // Ticket #4257
@@ -375,27 +375,27 @@ class TestString : public TestFixture {
375375 // Ticket #4257
376376 check (" bool foo() {\n "
377377 " MyString **str=OtherGetter();\n "
378- " return *str==\" bug\" ; }" , dinit (CheckOptions, $.filename = " test.c " ));
378+ " return *str==\" bug\" ; }" , dinit (CheckOptions, $.cpp = false ));
379379 ASSERT_EQUALS (" [test.c:3]: (warning) String literal compared with variable '*str'. Did you intend to use strcmp() instead?\n " , errout_str ());
380380
381381 // Ticket #4257
382382 check (" bool foo() {\n "
383383 " MyString str=OtherGetter2();\n "
384- " return &str==\" bug\" ; }" , dinit (CheckOptions, $.filename = " test.c " ));
384+ " return &str==\" bug\" ; }" , dinit (CheckOptions, $.cpp = false ));
385385 ASSERT_EQUALS (" [test.c:3]: (warning) String literal compared with variable '&str'. Did you intend to use strcmp() instead?\n " , errout_str ());
386386
387387 // Ticket #5734
388388 check (" int foo(char c) {\n "
389389 " return c == '4';}" );
390390 ASSERT_EQUALS (" " , errout_str ());
391391 check (" int foo(char c) {\n "
392- " return c == '4';}" , dinit (CheckOptions, $.filename = " test.c " ));
392+ " return c == '4';}" , dinit (CheckOptions, $.cpp = false ));
393393 ASSERT_EQUALS (" " , errout_str ());
394394 check (" int foo(char c) {\n "
395395 " return c == \" 42\" [0];}" );
396396 ASSERT_EQUALS (" " , errout_str ());
397397 check (" int foo(char c) {\n "
398- " return c == \" 42\" [0];}" , dinit (CheckOptions, $.filename = " test.c " ));
398+ " return c == \" 42\" [0];}" , dinit (CheckOptions, $.cpp = false ));
399399 ASSERT_EQUALS (" " , errout_str ());
400400
401401 // 5639 String literal compared with char buffer in a struct
@@ -413,7 +413,7 @@ class TestString : public TestFixture {
413413 " void foo() {\n "
414414 " struct Example example;\n "
415415 " if (example.buffer == \" test\" ) ;\n "
416- " }\n " , dinit (CheckOptions, $.filename = " test.c " ));
416+ " }\n " , dinit (CheckOptions, $.cpp = false ));
417417 ASSERT_EQUALS (" [test.c:6]: (warning) String literal compared with variable 'example.buffer'. Did you intend to use strcmp() instead?\n " , errout_str ());
418418
419419 // #9726
@@ -467,7 +467,7 @@ class TestString : public TestFixture {
467467
468468 check (" bool foo(char* c) {\n "
469469 " return *c == 0;\n "
470- " }" , dinit (CheckOptions, $.filename = " test.c " ));
470+ " }" , dinit (CheckOptions, $.cpp = false ));
471471 ASSERT_EQUALS (" " , errout_str ());
472472
473473 check (" bool foo(char* c) {\n "
0 commit comments