Skip to content

Commit

Permalink
Add test case for handle overloaded operator-> for CallExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
peckto committed Nov 14, 2024
1 parent a73c2c4 commit 0f8edd2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,41 @@ class CXXDeclarationTest {
assertEquals(p, opCall.base)
assertInvokes(opCall, op)
}

@Test
fun testCallExpressionOperator() {
val file = File("src/test/resources/cxx/operators/call_expression.cpp")
val result =
analyze(listOf(file), file.parentFile.toPath(), true) {
it.registerLanguage<CPPLanguage>()
}
assertNotNull(result)

var proxy = result.records["Proxy"]
assertNotNull(proxy)

var op = proxy.operators["operator->"]
assertNotNull(op)

var data = result.records["Data"]
assertNotNull(data)

var funcFoo = data.functions["foo"]
assertNotNull(funcFoo)

val p = result.refs["p"]
assertNotNull(p)
assertEquals(proxy.toType(), p.type)

var funcFooRef = result.memberExpressions["foo"]
assertNotNull(funcFooRef)
assertRefersTo(funcFooRef, funcFoo)

// we should now have an implicit call to our operator in-between "p" and "foo"
val opCall = funcFooRef.base
assertNotNull(opCall)
assertIs<OperatorCallExpression>(opCall)
assertEquals(p, opCall.base)
assertInvokes(opCall, op)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
struct Data {
int foo() {
return 1;
}
};

struct Proxy {
Data *data;
Proxy() {
data = new Data;
}
Data* operator->() {
return data;
}
};

int main() {
Proxy p;

int i = p->foo();
return 1;
}

0 comments on commit 0f8edd2

Please sign in to comment.