Skip to content

Commit 18a297b

Browse files
committed
A16-0-1: add extra testcases
1 parent 2193a22 commit 18a297b

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

cpp/autosar/test/rules/A16-0-1/PreProcessorShallOnlyBeUsedForCertainDirectivesPatterns.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
| test.cpp:11:1:11:37 | #define FUNCTIONLIKE_MACROTWO() 1 + 1 | Preprocessor directive used for conditional compilation. |
55
| test.cpp:35:1:35:26 | #elif OBJECTLIKE_MACRO > 0 | Preprocessor directive used for conditional compilation. |
66
| test.cpp:39:1:39:23 | #ifdef OBJECTLIKE_MACRO | Preprocessor directive used for conditional compilation. |
7+
| test.cpp:56:1:56:27 | #elif MACRO_ENABLED_OTHER_1 | Preprocessor directive used for conditional compilation. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options:--clang -std=c++14 --edg --diag_error=implicit_func_decl -nostdinc -I../../../../../cpp/common/test/includes/standard-library -D MACRO_ENABLED_NON_1 -D MACRO_ENABLED_OTHER_1

cpp/autosar/test/rules/A16-0-1/test.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,38 @@ int x0 = 0; // not present
3636
int x0 = 1; // present
3737
#endif // COMPLIANT
3838

39-
#ifdef OBJECTLIKE_MACRO // NON_COMPLIANT
40-
int x1 = 0; // present
41-
#elif OBJECTLIKE_MACRO > \
42-
-1 // COMPLIANT - by technicality of conditional compilation
39+
#ifdef OBJECTLIKE_MACRO // NON_COMPLIANT
40+
int x1 = 0; // present
41+
#elif OBJECTLIKE_MACRO > -1 // NON_COMPLIANT[FALSE_NEGATIVE] - known due to
42+
// database not containing elements
4343
int x1 = 1; // not present
44-
#endif // COMPLIANT
44+
#endif // COMPLIANT
45+
46+
// case 1 - first present only
47+
#ifdef MACRO_ENABLED_NON_1 // COMPLIANT
48+
#include <string> //present
49+
#elif MACRO_ENABLED_OTHER // NON_COMPLIANT[FALSE_NEGATIVE]
50+
int x = 1; // not present
51+
#endif
52+
53+
// case 2 - second present only
54+
#ifdef MACRO_ENABLED_NON // COMPLIANT
55+
#include <string> //not present
56+
#elif MACRO_ENABLED_OTHER_1 // NON_COMPLIANT
57+
int x = 1; // present
58+
#endif
59+
60+
// case 3 - neither present
61+
#ifdef MACRO_ENABLED_NON // COMPLIANT
62+
#include <string> //not present
63+
#elif MACRO_ENABLED_OTHER // NON_COMPLIANT[FALSE_NEGATIVE]
64+
int x = 1; // not present
65+
#endif
66+
67+
// case 4 - both look present but the second still not bc the condition is not
68+
// required to be evaluated
69+
#ifdef MACRO_ENABLED_NON_1 // COMPLIANT
70+
#include <string> //present
71+
#elif MACRO_ENABLED_OTHER_1 // NON_COMPLIANT[FALSE_NEGATIVE]
72+
int x = 1; // not present
73+
#endif

0 commit comments

Comments
 (0)