@@ -93,9 +93,9 @@ class TestPreprocessor : public TestFixture {
9393 }
9494
9595 // TODO: we should be using the actual Preprocessor implementation
96- static std::string getcodeforcfg (const Settings& settings, ErrorLogger& errorlogger, const std::string &filedata , const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr )
96+ static std::string getcodeforcfg (const Settings& settings, ErrorLogger& errorlogger, const char code[] , const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr )
9797 {
98- std::map<std::string, std::string> cfgcode = getcode (settings, errorlogger, filedata. c_str () , std::set<std::string>{cfg}, filename, inlineSuppression);
98+ std::map<std::string, std::string> cfgcode = getcode (settings, errorlogger, code , std::set<std::string>{cfg}, filename, inlineSuppression);
9999 const auto it = cfgcode.find (cfg);
100100 if (it == cfgcode.end ())
101101 return " " ;
@@ -430,7 +430,7 @@ class TestPreprocessor : public TestFixture {
430430
431431 void error3 () {
432432 const auto settings = dinit (Settings, $.userDefines = " __cplusplus" );
433- const std::string code ( " #error hello world!\n " ) ;
433+ const char code[] = " #error hello world!\n " ;
434434 (void )getcodeforcfg (settings, *this , code, " X" , " test.c" );
435435 ASSERT_EQUALS (" [test.c:1:0]: (error) #error hello world! [preprocessorErrorDirective]\n " , errout_str ());
436436 }
@@ -440,15 +440,15 @@ class TestPreprocessor : public TestFixture {
440440 // In included file
441441 {
442442 const auto settings = dinit (Settings, $.userDefines = " TEST" );
443- const std::string code ( " #file \" ab.h\"\n #error hello world!\n #endfile" ) ;
443+ const char code[] = " #file \" ab.h\"\n #error hello world!\n #endfile" ;
444444 (void )getcodeforcfg (settings, *this , code, " TEST" , " test.c" );
445445 ASSERT_EQUALS (" [ab.h:1:0]: (error) #error hello world! [preprocessorErrorDirective]\n " , errout_str ());
446446 }
447447
448448 // After including a file
449449 {
450450 const auto settings = dinit (Settings, $.userDefines = " TEST" );
451- const std::string code ( " #file \" ab.h\"\n\n #endfile\n #error aaa" ) ;
451+ const char code[] = " #file \" ab.h\"\n\n #endfile\n #error aaa" ;
452452 (void )getcodeforcfg (settings, *this , code, " TEST" , " test.c" );
453453 ASSERT_EQUALS (" [test.c:2:0]: (error) #error aaa [preprocessorErrorDirective]\n " , errout_str ());
454454 }
@@ -459,7 +459,7 @@ class TestPreprocessor : public TestFixture {
459459 const auto settings = dinit (Settings,
460460 $.userDefines = " TEST" ,
461461 $.force = true );
462- const std::string code ( " #error hello world!\n " ) ;
462+ const char code[] = " #error hello world!\n " ;
463463 (void )getcodeforcfg (settings, *this , code, " X" , " test.c" );
464464 ASSERT_EQUALS (" " , errout_str ());
465465 }
@@ -1974,10 +1974,10 @@ class TestPreprocessor : public TestFixture {
19741974 settings.inlineSuppressions = true ;
19751975 settings.checks .enable (Checks::missingInclude);
19761976
1977- const std::string code ( " // cppcheck-suppress missingInclude\n "
1978- " #include \" missing.h\"\n "
1979- " // cppcheck-suppress missingIncludeSystem\n "
1980- " #include <missing2.h>\n " ) ;
1977+ const char code[] = " // cppcheck-suppress missingInclude\n "
1978+ " #include \" missing.h\"\n "
1979+ " // cppcheck-suppress missingIncludeSystem\n "
1980+ " #include <missing2.h>\n " ;
19811981 SuppressionList inlineSuppr;
19821982 (void )getcodeforcfg (settings, *this , code, " " , " test.c" , &inlineSuppr);
19831983
@@ -2036,25 +2036,25 @@ class TestPreprocessor : public TestFixture {
20362036 }
20372037
20382038 void predefine1 () {
2039- const std::string src ( " #if defined X || Y\n "
2040- " Fred & Wilma\n "
2041- " #endif\n " ) ;
2042- std::string actual = getcodeforcfg (settings0, *this , src , " X=1" , " test.c" );
2039+ const char code[] = " #if defined X || Y\n "
2040+ " Fred & Wilma\n "
2041+ " #endif\n " ;
2042+ std::string actual = getcodeforcfg (settings0, *this , code , " X=1" , " test.c" );
20432043
20442044 ASSERT_EQUALS (" \n Fred & Wilma" , actual);
20452045 }
20462046
20472047 void predefine2 () {
2048- const std::string src ( " #if defined(X) && Y\n "
2049- " Fred & Wilma\n "
2050- " #endif\n " ) ;
2048+ const char code[] = " #if defined(X) && Y\n "
2049+ " Fred & Wilma\n "
2050+ " #endif\n " ;
20512051 {
2052- std::string actual = getcodeforcfg (settings0, *this , src , " X=1" , " test.c" );
2052+ std::string actual = getcodeforcfg (settings0, *this , code , " X=1" , " test.c" );
20532053 ASSERT_EQUALS (" " , actual);
20542054 }
20552055
20562056 {
2057- std::string actual = getcodeforcfg (settings0, *this , src , " X=1;Y=2" , " test.c" );
2057+ std::string actual = getcodeforcfg (settings0, *this , code , " X=1;Y=2" , " test.c" );
20582058 ASSERT_EQUALS (" \n Fred & Wilma" , actual);
20592059 }
20602060 }
@@ -2376,7 +2376,7 @@ class TestPreprocessor : public TestFixture {
23762376
23772377 void wrongPathOnErrorDirective () {
23782378 const auto settings = dinit (Settings, $.userDefines = " foo" );
2379- const std::string code ( " #error hello world!\n " ) ;
2379+ const char code[] = " #error hello world!\n " ;
23802380 (void )getcodeforcfg (settings, *this , code, " X" , " ./././test.c" );
23812381 ASSERT_EQUALS (" [test.c:1:0]: (error) #error hello world! [preprocessorErrorDirective]\n " , errout_str ());
23822382 }
@@ -2391,7 +2391,7 @@ class TestPreprocessor : public TestFixture {
23912391
23922392 ScopedFile header (" header.h" , " " );
23932393
2394- std::string code ( " #include \" header.h\" " ) ;
2394+ const char code[] = " #include \" header.h\" " ;
23952395 (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
23962396
23972397 ASSERT_EQUALS (" " , errout_str ());
@@ -2405,7 +2405,7 @@ class TestPreprocessor : public TestFixture {
24052405 settings.templateFormat = " simple" ; // has no effect
24062406 setTemplateFormat (" simple" );
24072407
2408- std::string code ( " #include \" header.h\" " ) ;
2408+ const char code[] = " #include \" header.h\" " ;
24092409 (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
24102410
24112411 ASSERT_EQUALS (" test.c:1:0: information: Include file: \" header.h\" not found. [missingInclude]\n " , errout_str ());
@@ -2421,7 +2421,7 @@ class TestPreprocessor : public TestFixture {
24212421
24222422 ScopedFile header (" header.h" , " " , " inc" );
24232423
2424- std::string code ( " #include \" header.h\" " ) ;
2424+ const char code[] = " #include \" header.h\" " ;
24252425 (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
24262426
24272427 ASSERT_EQUALS (" test.c:1:0: information: Include file: \" header.h\" not found. [missingInclude]\n " , errout_str ());
@@ -2438,7 +2438,7 @@ class TestPreprocessor : public TestFixture {
24382438
24392439 ScopedFile header (" header.h" , " " , " inc" );
24402440
2441- std::string code ( " #include \" inc/header.h\" " ) ;
2441+ const char code[] = " #include \" inc/header.h\" " ;
24422442 (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
24432443
24442444 ASSERT_EQUALS (" " , errout_str ());
@@ -2456,7 +2456,7 @@ class TestPreprocessor : public TestFixture {
24562456 ScopedFile header (" header.h" , " " , Path::getCurrentPath ());
24572457
24582458 std::string code (" #include \" " + header.path () + " \" " );
2459- (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2459+ (void )getcodeforcfg (settings, *this , code. c_str () , " " , " test.c" );
24602460
24612461 ASSERT_EQUALS (" " , errout_str ());
24622462 }
@@ -2472,7 +2472,7 @@ class TestPreprocessor : public TestFixture {
24722472 const std::string header = Path::join (Path::getCurrentPath (), " header.h" );
24732473
24742474 std::string code (" #include \" " + header + " \" " );
2475- (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2475+ (void )getcodeforcfg (settings, *this , code. c_str () , " " , " test.c" );
24762476
24772477 ASSERT_EQUALS (" test.c:1:0: information: Include file: \" " + header + " \" not found. [missingInclude]\n " , errout_str ());
24782478 }
@@ -2487,7 +2487,7 @@ class TestPreprocessor : public TestFixture {
24872487
24882488 ScopedFile header (" header.h" , " " );
24892489
2490- std::string code ( " #include <header.h>" ) ;
2490+ const char code[] = " #include <header.h>" ;
24912491 (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
24922492
24932493 ASSERT_EQUALS (" test.c:1:0: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n " , errout_str ());
@@ -2501,7 +2501,7 @@ class TestPreprocessor : public TestFixture {
25012501 settings.templateFormat = " simple" ; // has no effect
25022502 setTemplateFormat (" simple" );
25032503
2504- std::string code ( " #include <header.h>" ) ;
2504+ const char code[] = " #include <header.h>" ;
25052505 (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
25062506
25072507 ASSERT_EQUALS (" test.c:1:0: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n " , errout_str ());
@@ -2518,7 +2518,7 @@ class TestPreprocessor : public TestFixture {
25182518
25192519 ScopedFile header (" header.h" , " " , " system" );
25202520
2521- std::string code ( " #include <header.h>" ) ;
2521+ const char code[] = " #include <header.h>" ;
25222522 (void )getcodeforcfg (settings0, *this , code, " " , " test.c" );
25232523
25242524 ASSERT_EQUALS (" " , errout_str ());
@@ -2536,7 +2536,7 @@ class TestPreprocessor : public TestFixture {
25362536 ScopedFile header (" header.h" , " " , Path::getCurrentPath ());
25372537
25382538 std::string code (" #include <" + header.path () + " >" );
2539- (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2539+ (void )getcodeforcfg (settings, *this , code. c_str () , " " , " test.c" );
25402540
25412541 ASSERT_EQUALS (" " , errout_str ());
25422542 }
@@ -2552,7 +2552,7 @@ class TestPreprocessor : public TestFixture {
25522552 const std::string header = Path::join (Path::getCurrentPath (), " header.h" );
25532553
25542554 std::string code (" #include <" + header + " >" );
2555- (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2555+ (void )getcodeforcfg (settings, *this , code. c_str () , " " , " test.c" );
25562556
25572557 ASSERT_EQUALS (" test.c:1:0: information: Include file: <" + header + " > not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n " , errout_str ());
25582558 }
@@ -2568,10 +2568,10 @@ class TestPreprocessor : public TestFixture {
25682568 ScopedFile header (" header.h" , " " );
25692569 ScopedFile header2 (" header2.h" , " " );
25702570
2571- std::string code ( " #include \" missing.h\"\n "
2572- " #include <header.h>\n "
2573- " #include <missing2.h>\n "
2574- " #include \" header2.h\" " ) ;
2571+ const char code[] = " #include \" missing.h\"\n "
2572+ " #include <header.h>\n "
2573+ " #include <missing2.h>\n "
2574+ " #include \" header2.h\" " ;
25752575 (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
25762576
25772577 ASSERT_EQUALS (" test.c:1:0: information: Include file: \" missing.h\" not found. [missingInclude]\n "
@@ -2608,7 +2608,7 @@ class TestPreprocessor : public TestFixture {
26082608 " #include \" " + missing3 + " \"\n "
26092609 " #include <" + header6.path () + " >\n "
26102610 " #include <" + missing4 + " >\n " );
2611- (void )getcodeforcfg (settings, *this , code, " " , " test.c" );
2611+ (void )getcodeforcfg (settings, *this , code. c_str () , " " , " test.c" );
26122612
26132613 ASSERT_EQUALS (" test.c:1:0: information: Include file: \" missing.h\" not found. [missingInclude]\n "
26142614 " test.c:2:0: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n "
0 commit comments