I'm experimenting with getting the target function for virtual function calls in C++. The documentation for FunctionCall suggests that getTarget() should return the 'most-specific function in the override tree', but I'm not sure if that is the behavior I'm observing.
In the example below, I have three calls, where I would expect the target for CALL1 to be a the ChildClass target, CALL2 the ParentClass target, and CALL3to be potentially from both ChildClass and ParentClass. In all cases, however, codeql reports the target as being the ParentClass function. Is that the expected result to getTarget() for FunctionCall, and is there a way to get my expected result with codeql?
#include <iostream>
#include <cstdlib>
using namespace std;
class ParentClass
{
public:
virtual char* test_func()
{
return "PARENT: test_func";
}
};
class ChildClass: public ParentClass
{
public:
virtual char* test_func()
{
return "CHILD: test_func";
}
};
int main(int argc, char** argv)
{
ParentClass *c;
if(argc > 1)
{
c = new ChildClass();
// CALL1
c->test_func();
}
else
{
c = new ParentClass();
// CALL2
c->test_func();
}
// CALL3
c->test_func();
}
The text was updated successfully, but these errors were encountered:
I'm experimenting with getting the target function for virtual function calls in C++. The documentation for
FunctionCallsuggests thatgetTarget()should return the 'most-specific function in the override tree', but I'm not sure if that is the behavior I'm observing.In the example below, I have three calls, where I would expect the target for
CALL1to be a theChildClasstarget,CALL2the ParentClass target, andCALL3to be potentially from bothChildClassandParentClass. In all cases, however, codeql reports the target as being theParentClassfunction. Is that the expected result togetTarget()forFunctionCall, and is there a way to get my expected result with codeql?The text was updated successfully, but these errors were encountered: