Skip to content

Conversation

@guitargeek
Copy link
Contributor


The current implementation of the CPPMethod::GetPriority function considers only direct bases of the class type given as input parameter to a certain function. This can lead to situations which are easily distinguishable but that lead to the same overload being called when passing instances of different classes of the same inheritance tree.

For example,

import ROOT

ROOT.gInterpreter.Declare(
'''
class A {};
class B: public A {};
class C: public B {};

void myfunc(const B &b){
    std::cout << "B" << std::endl;
}

void myfunc(const C &c){
    std::cout << "C" << std::endl;
}

''')

ROOT.myfunc(ROOT.B())
ROOT.myfunc(ROOT.C())

Prints B for both function calls. This commit introduces a new function in cppyy that retrieves the number of bases in the longest branch of the inheritance tree for a certain class. This helps better distinguish cases like the one above, that are now solved.

The new logic still does not solve another issue, namely the fact that in certain situations which would throw errors in C++ due to their ambiguity, cppyy resorts to calling the function overload with the highest priority. A couple of tests have been added in roottest to show both behaviours.

The current implementation of the CPPMethod::GetPriority function
considers only direct bases of the class type given as input parameter
to a certain function. This can lead to situations which are easily
distinguishable but that lead to the same overload being called when
passing instances of different classes of the same inheritance tree.

For example,
```python
import ROOT

ROOT.gInterpreter.Declare(
'''
class A {};
class B: public A {};
class C: public B {};

void myfunc(const B &b){
    std::cout << "B" << std::endl;
}

void myfunc(const C &c){
    std::cout << "C" << std::endl;
}

''')

ROOT.myfunc(ROOT.B())
ROOT.myfunc(ROOT.C())
```

Prints `B` for both function calls. This commit introduces a new
function in cppyy that retrieves the number of bases in the longest
branch of the inheritance tree for a certain class. This helps better
distinguish cases like the one above, that are now solved.

The new logic still does not solve another issue, namely the fact that
in certain situations which would throw errors in C++ due to their
ambiguity, cppyy resorts to calling the function overload with the
highest priority. A couple of tests have been added in roottest to show
both behaviours.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants