Skip to content

Commit f337c9f

Browse files
authored
Merge pull request #888 from dave-bartolomeo/dave/Capture
C++: Update captures test for closure fields extractor fix
2 parents 87c5872 + f460d2c commit f337c9f

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

cpp/ql/test/library-tests/lambdas/captures/captures.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,10 @@ struct foo {
1010
b(x + 1);
1111
};
1212
}
13+
14+
static void c(int x) {
15+
[x] {
16+
c(0); // `x` is unused, but still captured.
17+
};
18+
}
1319
};
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
| captures.cpp:3:6:3:6 | x | explicit |
2-
| captures.cpp:3:9:3:12 | (captured this) | explicit |
3-
| captures.cpp:3:9:3:12 | x | explicit |
4-
| captures.cpp:10:7:10:7 | (captured this) | implicit |
5-
| captures.cpp:10:9:10:9 | (captured this) | implicit |
6-
| captures.cpp:10:9:10:9 | x | implicit |
7-
| end_pos.cpp:9:17:9:18 | ii | explicit |
1+
| captures.cpp:3:6:3:6 | x | explicit | 1 |
2+
| captures.cpp:3:9:3:12 | (captured this) | explicit | 2 |
3+
| captures.cpp:10:7:10:7 | (captured this) | implicit | 1 |
4+
| captures.cpp:10:9:10:9 | x | implicit | 2 |
5+
| captures.cpp:15:6:15:6 | x | explicit | 1 |
6+
| end_pos.cpp:9:17:9:18 | ii | explicit | 1 |
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import cpp
22

3-
from LambdaCapture lc, string mode
4-
where if lc.isImplicit() then mode = "implicit" else mode = "explicit"
5-
select lc, mode
3+
from LambdaCapture lc, string mode, int index
4+
where
5+
exists(LambdaExpression le | le.getCapture(index) = lc) and
6+
if lc.isImplicit() then mode = "implicit" else mode = "explicit"
7+
select lc, mode, index

cpp/ql/test/library-tests/lambdas/captures/elements.expected

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,34 @@
6565
| captures.cpp:10:13:10:13 | 1 |
6666
| captures.cpp:11:5:11:5 | return ... |
6767
| captures.cpp:12:3:12:3 | return ... |
68+
| captures.cpp:14:15:14:15 | c |
69+
| captures.cpp:14:15:14:15 | definition of c |
70+
| captures.cpp:14:21:14:21 | definition of x |
71+
| captures.cpp:14:21:14:21 | x |
72+
| captures.cpp:14:24:18:3 | { ... } |
73+
| captures.cpp:15:5:15:5 | (constructor) |
74+
| captures.cpp:15:5:15:5 | (constructor) |
75+
| captures.cpp:15:5:15:5 | (constructor) |
76+
| captures.cpp:15:5:15:5 | declaration of (null) |
77+
| captures.cpp:15:5:15:5 | declaration of (null) |
78+
| captures.cpp:15:5:15:5 | definition of (null) |
79+
| captures.cpp:15:5:15:5 | definition of operator= |
80+
| captures.cpp:15:5:15:5 | operator= |
81+
| captures.cpp:15:5:17:5 | [...](...){...} |
82+
| captures.cpp:15:5:17:5 | {...} |
83+
| captures.cpp:15:5:17:6 | ExprStmt |
84+
| captures.cpp:15:6:15:6 | definition of x |
85+
| captures.cpp:15:6:15:6 | x |
86+
| captures.cpp:15:6:15:6 | x |
87+
| captures.cpp:15:9:15:9 | definition of operator() |
88+
| captures.cpp:15:9:15:9 | operator() |
89+
| captures.cpp:15:9:17:5 | { ... } |
90+
| captures.cpp:16:7:16:7 | call to c |
91+
| captures.cpp:16:7:16:11 | ExprStmt |
92+
| captures.cpp:16:9:16:9 | 0 |
93+
| captures.cpp:16:13:16:49 | // `x` is unused, but still captured. |
94+
| captures.cpp:17:5:17:5 | return ... |
95+
| captures.cpp:18:3:18:3 | return ... |
6896
| end_pos.cpp:0:0:0:0 | end_pos.cpp |
6997
| end_pos.cpp:2:1:2:14 | #define OPEN { |
7098
| end_pos.cpp:3:6:3:10 | definition of igFun |
@@ -131,6 +159,8 @@
131159
| file://:0:0:0:0 | const lambda [] type at line 9, col. 5 *const |
132160
| file://:0:0:0:0 | const lambda [] type at line 9, col. 15 |
133161
| file://:0:0:0:0 | const lambda [] type at line 9, col. 15 & |
162+
| file://:0:0:0:0 | const lambda [] type at line 15, col. 5 |
163+
| file://:0:0:0:0 | const lambda [] type at line 15, col. 5 & |
134164
| file://:0:0:0:0 | declaration of 1st parameter |
135165
| file://:0:0:0:0 | declaration of 1st parameter |
136166
| file://:0:0:0:0 | declaration of 1st parameter |
@@ -142,6 +172,10 @@
142172
| file://:0:0:0:0 | declaration of 1st parameter |
143173
| file://:0:0:0:0 | declaration of 1st parameter |
144174
| file://:0:0:0:0 | declaration of 1st parameter |
175+
| file://:0:0:0:0 | declaration of 1st parameter |
176+
| file://:0:0:0:0 | declaration of 1st parameter |
177+
| file://:0:0:0:0 | declaration of 1st parameter |
178+
| file://:0:0:0:0 | decltype([...](...){...}) |
145179
| file://:0:0:0:0 | decltype([...](...){...}) |
146180
| file://:0:0:0:0 | decltype([...](...){...}) |
147181
| file://:0:0:0:0 | decltype([...](...){...}) |
@@ -164,6 +198,8 @@
164198
| file://:0:0:0:0 | lambda [] type at line 9, col. 5 * |
165199
| file://:0:0:0:0 | lambda [] type at line 9, col. 15 & |
166200
| file://:0:0:0:0 | lambda [] type at line 9, col. 15 && |
201+
| file://:0:0:0:0 | lambda [] type at line 15, col. 5 & |
202+
| file://:0:0:0:0 | lambda [] type at line 15, col. 5 && |
167203
| file://:0:0:0:0 | operator= |
168204
| file://:0:0:0:0 | operator= |
169205
| file://:0:0:0:0 | overflow_arg_area |
@@ -180,6 +216,9 @@
180216
| file://:0:0:0:0 | p#0 |
181217
| file://:0:0:0:0 | p#0 |
182218
| file://:0:0:0:0 | p#0 |
219+
| file://:0:0:0:0 | p#0 |
220+
| file://:0:0:0:0 | p#0 |
221+
| file://:0:0:0:0 | p#0 |
183222
| file://:0:0:0:0 | reg_save_area |
184223
| file://:0:0:0:0 | this |
185224
| file://:0:0:0:0 | this |

0 commit comments

Comments
 (0)