File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed
cpg-language-cxx/src/test
kotlin/de/fraunhofer/aisec/cpg/frontends/cxx Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -306,4 +306,41 @@ class CXXDeclarationTest {
306
306
assertEquals(p, opCall.base)
307
307
assertInvokes(opCall, op)
308
308
}
309
+
310
+ @Test
311
+ fun testCallExpressionOperator () {
312
+ val file = File (" src/test/resources/cxx/operators/call_expression.cpp" )
313
+ val result =
314
+ analyze(listOf (file), file.parentFile.toPath(), true ) {
315
+ it.registerLanguage<CPPLanguage >()
316
+ }
317
+ assertNotNull(result)
318
+
319
+ var proxy = result.records[" Proxy" ]
320
+ assertNotNull(proxy)
321
+
322
+ var op = proxy.operators[" operator->" ]
323
+ assertNotNull(op)
324
+
325
+ var data = result.records[" Data" ]
326
+ assertNotNull(data)
327
+
328
+ var funcFoo = data.functions[" foo" ]
329
+ assertNotNull(funcFoo)
330
+
331
+ val p = result.refs[" p" ]
332
+ assertNotNull(p)
333
+ assertEquals(proxy.toType(), p.type)
334
+
335
+ var funcFooRef = result.memberExpressions[" foo" ]
336
+ assertNotNull(funcFooRef)
337
+ assertRefersTo(funcFooRef, funcFoo)
338
+
339
+ // we should now have an implicit call to our operator in-between "p" and "foo"
340
+ val opCall = funcFooRef.base
341
+ assertNotNull(opCall)
342
+ assertIs<OperatorCallExpression >(opCall)
343
+ assertEquals(p, opCall.base)
344
+ assertInvokes(opCall, op)
345
+ }
309
346
}
Original file line number Diff line number Diff line change
1
+ struct Data {
2
+ int foo () {
3
+ return 1 ;
4
+ }
5
+ };
6
+
7
+ struct Proxy {
8
+ Data *data;
9
+ Proxy () {
10
+ data = new Data;
11
+ }
12
+ Data* operator ->() {
13
+ return data;
14
+ }
15
+ };
16
+
17
+ int main () {
18
+ Proxy p;
19
+
20
+ int i = p->foo ();
21
+ return 1 ;
22
+ }
23
+
You can’t perform that action at this time.
0 commit comments