Skip to content

Commit 66d156d

Browse files
authored
Merge pull request #17608 from jketema/macro-expansion-tests
C++: Add more macro expansion tests
2 parents 2427227 + e73d1c7 commit 66d156d

File tree

2 files changed

+235
-15
lines changed

2 files changed

+235
-15
lines changed

cpp/ql/test/library-tests/macros/inmacroexpansion/inmacroexpansion.expected

Lines changed: 156 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,168 @@
22
| file://:0:0:0:0 | (unnamed parameter 0) | false |
33
| file://:0:0:0:0 | __super | false |
44
| file://:0:0:0:0 | __va_list_tag | false |
5+
| file://:0:0:0:0 | decltype([...](...){...}) | false |
56
| file://:0:0:0:0 | operator= | false |
67
| file://:0:0:0:0 | operator= | false |
78
| test.cpp:0:0:0:0 | test.cpp | false |
8-
| test.cpp:2:1:2:61 | #define FOO class S{int i; void f(void) { int j; return; } }; | false |
9+
| test.cpp:2:1:2:68 | #define CLASS_DECL class S{int i; void f(void) { int j; return; } }; | false |
910
| test.cpp:4:1:4:1 | S | false |
1011
| test.cpp:4:1:4:1 | declaration of S | false |
1112
| test.cpp:4:1:4:1 | declaration of operator= | false |
1213
| test.cpp:4:1:4:1 | declaration of operator= | false |
1314
| test.cpp:4:1:4:1 | operator= | false |
1415
| test.cpp:4:1:4:1 | operator= | false |
15-
| test.cpp:4:1:4:3 | FOO | false |
16-
| test.cpp:4:1:4:3 | S | false |
17-
| test.cpp:4:1:4:3 | declaration | true |
18-
| test.cpp:4:1:4:3 | definition of S | true |
19-
| test.cpp:4:1:4:3 | definition of f | true |
20-
| test.cpp:4:1:4:3 | definition of i | true |
21-
| test.cpp:4:1:4:3 | definition of j | true |
22-
| test.cpp:4:1:4:3 | f | false |
23-
| test.cpp:4:1:4:3 | i | false |
24-
| test.cpp:4:1:4:3 | j | true |
25-
| test.cpp:4:1:4:3 | return ... | true |
26-
| test.cpp:4:1:4:3 | { ... } | true |
16+
| test.cpp:4:1:4:10 | CLASS_DECL | false |
17+
| test.cpp:4:1:4:10 | S | false |
18+
| test.cpp:4:1:4:10 | declaration | true |
19+
| test.cpp:4:1:4:10 | definition of S | true |
20+
| test.cpp:4:1:4:10 | definition of f | true |
21+
| test.cpp:4:1:4:10 | definition of i | true |
22+
| test.cpp:4:1:4:10 | definition of j | true |
23+
| test.cpp:4:1:4:10 | f | false |
24+
| test.cpp:4:1:4:10 | i | false |
25+
| test.cpp:4:1:4:10 | j | true |
26+
| test.cpp:4:1:4:10 | return ... | true |
27+
| test.cpp:4:1:4:10 | { ... } | true |
28+
| test.cpp:6:1:6:42 | #define FUNCTION_DECL void f1() { int k; } | false |
29+
| test.cpp:8:1:8:13 | FUNCTION_DECL | false |
30+
| test.cpp:8:1:8:13 | declaration | true |
31+
| test.cpp:8:1:8:13 | definition of f1 | true |
32+
| test.cpp:8:1:8:13 | definition of k | true |
33+
| test.cpp:8:1:8:13 | f1 | false |
34+
| test.cpp:8:1:8:13 | k | true |
35+
| test.cpp:8:1:8:13 | return ... | true |
36+
| test.cpp:8:1:8:13 | { ... } | true |
37+
| test.cpp:10:1:10:33 | #define VARIABLE_DECL int v1 = 1; | false |
38+
| test.cpp:12:1:12:13 | 1 | true |
39+
| test.cpp:12:1:12:13 | VARIABLE_DECL | false |
40+
| test.cpp:12:1:12:13 | definition of v1 | true |
41+
| test.cpp:12:1:12:13 | initializer for v1 | true |
42+
| test.cpp:12:1:12:13 | v1 | true |
43+
| test.cpp:14:1:14:35 | #define TYPE_DECL_1 typedef int t1; | false |
44+
| test.cpp:16:1:16:11 | TYPE_DECL_1 | false |
45+
| test.cpp:16:1:16:11 | declaration of t1 | true |
46+
| test.cpp:16:1:16:11 | t1 | false |
47+
| test.cpp:18:1:18:35 | #define TYPE_DECL_2 using t2 = int; | false |
48+
| test.cpp:20:1:20:11 | TYPE_DECL_2 | false |
49+
| test.cpp:20:1:20:11 | declaration of t2 | true |
50+
| test.cpp:20:1:20:11 | t2 | false |
51+
| test.cpp:22:1:22:47 | #define NAMESPACE_DECL namespace ns { int v2; } | false |
52+
| test.cpp:24:1:24:14 | NAMESPACE_DECL | false |
53+
| test.cpp:24:1:24:14 | definition of v2 | true |
54+
| test.cpp:24:1:24:14 | ns | false |
55+
| test.cpp:24:1:24:14 | ns | false |
56+
| test.cpp:24:1:24:14 | v2 | true |
57+
| test.cpp:26:1:26:43 | #define USING_NAMESPACE using namespace ns; | false |
58+
| test.cpp:28:1:28:34 | #define ENUM_CONSTANT enum_element | false |
59+
| test.cpp:30:12:30:21 | definition of enum_class | false |
60+
| test.cpp:30:12:30:21 | enum_class | false |
61+
| test.cpp:30:25:30:37 | ENUM_CONSTANT | false |
62+
| test.cpp:30:25:30:37 | enum_element | false |
63+
| test.cpp:32:1:32:41 | #define USING_ENUM using enum enum_class; | false |
64+
| test.cpp:34:1:34:10 | USING_ENUM | false |
65+
| test.cpp:34:1:34:10 | using enum enum_class | false |
66+
| test.cpp:36:1:36:48 | #define STATIC_ASSERT static_assert(1 == 1, ""); | false |
67+
| test.cpp:38:1:38:13 | 1 | true |
68+
| test.cpp:38:1:38:13 | 1 | true |
69+
| test.cpp:38:1:38:13 | ... == ... | true |
70+
| test.cpp:38:1:38:13 | STATIC_ASSERT | false |
71+
| test.cpp:38:1:38:13 | static_assert(..., "") | false |
72+
| test.cpp:40:1:40:42 | #define ATTRIBUTE [[nodiscard("reason1")]] | false |
73+
| test.cpp:42:1:42:9 | ATTRIBUTE | false |
74+
| test.cpp:42:1:42:9 | nodiscard | false |
75+
| test.cpp:42:1:42:9 | reason1 | false |
76+
| test.cpp:42:1:42:9 | reason1 | true |
77+
| test.cpp:43:5:43:6 | declaration of f2 | false |
78+
| test.cpp:43:5:43:6 | f2 | false |
79+
| test.cpp:45:1:45:31 | #define ATTRIBUTE_ARG "reason2" | false |
80+
| test.cpp:47:3:47:11 | nodiscard | false |
81+
| test.cpp:47:13:47:25 | ATTRIBUTE_ARG | false |
82+
| test.cpp:47:13:47:25 | reason2 | false |
83+
| test.cpp:47:13:47:25 | reason2 | true |
84+
| test.cpp:48:5:48:6 | declaration of f3 | false |
85+
| test.cpp:48:5:48:6 | f3 | false |
86+
| test.cpp:50:1:50:16 | #define TYPE int | false |
87+
| test.cpp:52:1:52:4 | TYPE | false |
88+
| test.cpp:52:6:52:7 | definition of v3 | true |
89+
| test.cpp:52:6:52:7 | v3 | true |
90+
| test.cpp:52:11:52:11 | 1 | false |
91+
| test.cpp:52:11:52:11 | initializer for v3 | false |
92+
| test.cpp:54:1:54:29 | #define DERIVATION : public S | false |
93+
| test.cpp:56:7:56:7 | T | false |
94+
| test.cpp:56:7:56:7 | T | false |
95+
| test.cpp:56:7:56:7 | declaration of T | false |
96+
| test.cpp:56:7:56:7 | declaration of operator= | false |
97+
| test.cpp:56:7:56:7 | declaration of operator= | false |
98+
| test.cpp:56:7:56:7 | definition of T | false |
99+
| test.cpp:56:7:56:7 | operator= | false |
100+
| test.cpp:56:7:56:7 | operator= | false |
101+
| test.cpp:56:9:56:18 | DERIVATION | false |
102+
| test.cpp:56:9:56:18 | derivation | false |
103+
| test.cpp:58:1:58:31 | #define FRIEND friend int f3(); | false |
104+
| test.cpp:60:7:60:7 | U | false |
105+
| test.cpp:60:7:60:7 | declaration of operator= | false |
106+
| test.cpp:60:7:60:7 | declaration of operator= | false |
107+
| test.cpp:60:7:60:7 | definition of U | false |
108+
| test.cpp:60:7:60:7 | operator= | false |
109+
| test.cpp:60:7:60:7 | operator= | false |
110+
| test.cpp:61:3:61:8 | FRIEND | false |
111+
| test.cpp:61:3:61:8 | U's friend | false |
112+
| test.cpp:64:1:64:24 | #define NAME_QUAL_1 ns:: | false |
113+
| test.cpp:66:1:66:22 | #define NAME_QUAL_2 ns | false |
114+
| test.cpp:68:1:68:19 | #define LOCAL_VAR m | false |
115+
| test.cpp:70:6:70:7 | definition of f4 | false |
116+
| test.cpp:70:6:70:7 | f4 | false |
117+
| test.cpp:70:11:76:1 | { ... } | false |
118+
| test.cpp:71:5:71:8 | ns:: | false |
119+
| test.cpp:71:5:71:15 | NAME_QUAL_1 | false |
120+
| test.cpp:71:5:71:18 | v2 | false |
121+
| test.cpp:71:5:71:19 | ExprStmt | false |
122+
| test.cpp:72:5:72:8 | ns:: | false |
123+
| test.cpp:72:5:72:15 | NAME_QUAL_2 | false |
124+
| test.cpp:72:5:72:21 | v2 | false |
125+
| test.cpp:72:5:72:22 | ExprStmt | false |
126+
| test.cpp:73:5:73:23 | declaration | false |
127+
| test.cpp:73:9:73:17 | LOCAL_VAR | false |
128+
| test.cpp:73:9:73:17 | definition of m | true |
129+
| test.cpp:73:9:73:17 | m | true |
130+
| test.cpp:73:20:73:22 | 42 | false |
131+
| test.cpp:73:20:73:22 | initializer for m | false |
132+
| test.cpp:74:5:74:41 | declaration | false |
133+
| test.cpp:74:10:74:10 | definition of l | false |
134+
| test.cpp:74:10:74:10 | l | false |
135+
| test.cpp:74:13:74:40 | [...](...){...} | false |
136+
| test.cpp:74:13:74:40 | initializer for l | false |
137+
| test.cpp:74:13:74:40 | {...} | false |
138+
| test.cpp:74:14:74:14 | (unnamed constructor) | false |
139+
| test.cpp:74:14:74:14 | (unnamed constructor) | false |
140+
| test.cpp:74:14:74:14 | (unnamed constructor) | false |
141+
| test.cpp:74:14:74:14 | declaration of (unnamed constructor) | false |
142+
| test.cpp:74:14:74:14 | declaration of (unnamed constructor) | false |
143+
| test.cpp:74:14:74:14 | definition of (unnamed constructor) | false |
144+
| test.cpp:74:14:74:14 | definition of operator= | false |
145+
| test.cpp:74:14:74:14 | operator= | false |
146+
| test.cpp:74:15:74:15 | definition of m | false |
147+
| test.cpp:74:15:74:15 | m | false |
148+
| test.cpp:74:15:74:15 | m | false |
149+
| test.cpp:74:15:74:23 | LOCAL_VAR | false |
150+
| test.cpp:74:15:74:23 | m | true |
151+
| test.cpp:74:25:74:25 | definition of operator() | false |
152+
| test.cpp:74:25:74:25 | operator() | false |
153+
| test.cpp:74:28:74:40 | { ... } | false |
154+
| test.cpp:74:30:74:38 | return ... | false |
155+
| test.cpp:74:37:74:37 | (int)... | false |
156+
| test.cpp:75:5:75:5 | (const lambda [] type at line 74, col. 14)... | false |
157+
| test.cpp:75:5:75:5 | l | false |
158+
| test.cpp:75:5:75:8 | ExprStmt | false |
159+
| test.cpp:75:6:75:6 | call to operator() | false |
160+
| test.cpp:76:1:76:1 | return ... | false |
161+
| test.cpp:78:1:78:15 | #define ID(x) x | false |
162+
| test.cpp:79:1:79:23 | #define NESTED(x) ID(x) | false |
163+
| test.cpp:80:5:80:6 | definition of v4 | false |
164+
| test.cpp:80:5:80:6 | v4 | false |
165+
| test.cpp:80:10:80:18 | ID(x) | false |
166+
| test.cpp:80:10:80:18 | NESTED(x) | false |
167+
| test.cpp:80:17:80:17 | 1 | true |
168+
| test.cpp:80:17:80:17 | initializer for v4 | true |
169+
| test.cpp:82:1:82:39 | // semmle-extractor-options: -std=c++20 | false |
Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,82 @@
11

2-
#define FOO class S{int i; void f(void) { int j; return; } };
2+
#define CLASS_DECL class S{int i; void f(void) { int j; return; } };
33

4-
FOO
4+
CLASS_DECL
55

6+
#define FUNCTION_DECL void f1() { int k; }
7+
8+
FUNCTION_DECL
9+
10+
#define VARIABLE_DECL int v1 = 1;
11+
12+
VARIABLE_DECL
13+
14+
#define TYPE_DECL_1 typedef int t1;
15+
16+
TYPE_DECL_1
17+
18+
#define TYPE_DECL_2 using t2 = int;
19+
20+
TYPE_DECL_2
21+
22+
#define NAMESPACE_DECL namespace ns { int v2; }
23+
24+
NAMESPACE_DECL
25+
26+
#define USING_NAMESPACE using namespace ns;
27+
28+
#define ENUM_CONSTANT enum_element
29+
30+
enum class enum_class { ENUM_CONSTANT };
31+
32+
#define USING_ENUM using enum enum_class;
33+
34+
USING_ENUM
35+
36+
#define STATIC_ASSERT static_assert(1 == 1, "");
37+
38+
STATIC_ASSERT
39+
40+
#define ATTRIBUTE [[nodiscard("reason1")]]
41+
42+
ATTRIBUTE
43+
int f2();
44+
45+
#define ATTRIBUTE_ARG "reason2"
46+
47+
[[nodiscard(ATTRIBUTE_ARG)]]
48+
int f3();
49+
50+
#define TYPE int
51+
52+
TYPE v3 = 1;
53+
54+
#define DERIVATION : public S
55+
56+
class T DERIVATION {};
57+
58+
#define FRIEND friend int f3();
59+
60+
class U {
61+
FRIEND
62+
};
63+
64+
#define NAME_QUAL_1 ns::
65+
66+
#define NAME_QUAL_2 ns
67+
68+
#define LOCAL_VAR m
69+
70+
void f4() {
71+
NAME_QUAL_1 v2;
72+
NAME_QUAL_2 :: v2;
73+
int LOCAL_VAR = 42;
74+
auto l = [LOCAL_VAR]() { return m; };
75+
l();
76+
}
77+
78+
#define ID(x) x
79+
#define NESTED(x) ID(x)
80+
int v4 = NESTED(1);
81+
82+
// semmle-extractor-options: -std=c++20

0 commit comments

Comments
 (0)