@@ -238,6 +238,9 @@ class TestPreprocessor : public TestFixture {
238
238
TEST_CASE (predefine5); // automatically define __cplusplus
239
239
TEST_CASE (predefine6); // automatically define __STDC_VERSION__
240
240
241
+
242
+ TEST_CASE (strictAnsi);
243
+
241
244
TEST_CASE (invalidElIf); // #2942 segfault
242
245
243
246
// Preprocessor::getConfigs
@@ -289,6 +292,8 @@ class TestPreprocessor : public TestFixture {
289
292
TEST_CASE (testMissingIncludeMixed);
290
293
TEST_CASE (testMissingIncludeCheckConfig);
291
294
295
+ TEST_CASE (hasInclude);
296
+
292
297
TEST_CASE (limitsDefines);
293
298
294
299
TEST_CASE (hashCalculation);
@@ -2036,6 +2041,23 @@ class TestPreprocessor : public TestFixture {
2036
2041
ASSERT_EQUALS (" " , PreprocessorHelper::getcode (settings0, *this , code, " " , " test.cpp" ));
2037
2042
}
2038
2043
2044
+ void strictAnsi () {
2045
+ const char code[] = " #ifdef __STRICT_ANSI__\n 123\n #endif" ;
2046
+ Settings settings;
2047
+
2048
+ settings.standards .setStd (" gnu99" );
2049
+ ASSERT_EQUALS (" " , PreprocessorHelper::getcode (settings, *this , code, " " , " test.c" ));
2050
+
2051
+ settings.standards .setStd (" c99" );
2052
+ ASSERT_EQUALS (" \n 123" , PreprocessorHelper::getcode (settings, *this , code, " " , " test.c" ));
2053
+
2054
+ settings.standards .setStd (" gnu++11" );
2055
+ ASSERT_EQUALS (" " , PreprocessorHelper::getcode (settings, *this , code, " " , " test.cpp" ));
2056
+
2057
+ settings.standards .setStd (" c++11" );
2058
+ ASSERT_EQUALS (" \n 123" , PreprocessorHelper::getcode (settings, *this , code, " " , " test.cpp" ));
2059
+ }
2060
+
2039
2061
void invalidElIf () {
2040
2062
// #2942 - segfault
2041
2063
const char code[] = " #elif (){\n " ;
@@ -2547,6 +2569,23 @@ class TestPreprocessor : public TestFixture {
2547
2569
" test.c:11:0: information: Include file: <" + missing4 + " > not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n " , errout_str ());
2548
2570
}
2549
2571
2572
+ void hasInclude () {
2573
+ const char code[] = " #if __has_include(<directory/non-existent-header.h>)\n 123\n #endif" ;
2574
+ Settings settings;
2575
+
2576
+ settings.standards .setStd (" c++11" );
2577
+ ASSERT_EQUALS (" " , PreprocessorHelper::getcode (settings, *this , code, " " , " test.cpp" ));
2578
+ ASSERT_EQUALS (" [test.cpp:1:0]: (error) failed to evaluate #if condition, division/modulo by zero [preprocessorErrorDirective]\n " , errout_str ());
2579
+
2580
+ settings.standards .setStd (" c++17" );
2581
+ ASSERT_EQUALS (" " , PreprocessorHelper::getcode (settings, *this , code, " " , " test.cpp" ));
2582
+ ASSERT_EQUALS (" " , errout_str ());
2583
+
2584
+ settings.standards .setStd (" gnu++11" );
2585
+ ASSERT_EQUALS (" " , PreprocessorHelper::getcode (settings, *this , code, " " , " test.cpp" ));
2586
+ ASSERT_EQUALS (" " , errout_str ());
2587
+ }
2588
+
2550
2589
void limitsDefines () {
2551
2590
// #11928 / #10045
2552
2591
const char code[] = " void f(long l) {\n "
0 commit comments