[PyROOT] cppyy can't find the correct template overload function


ROOT Version: 6.24.06
Platform: lxplus

In PyROOT, if one overloads function templates with argument types TH1* and TAxis*, only the function that is defined first will be loaded.

Reproducer:

import ROOT
import cppyy
cppyy.cppdef(r"""\
        template<typename T>
        T foo1(TH1* h)
        {
            return (T)1;
        }
        template<typename T>
        T foo1(TAxis* ax)
        {
            return (T)1;
        }
        template<typename T>
        T foo2(TAxis* h)
        {
            return (T)1;
        }
        template<typename T>
        T foo2(TH1* ax)
        {
            return (T)1;
        }
        """)

h = ROOT.TH1D("h", "h", 1, 0, 1)
ax = h.GetXaxis()

# works
ROOT.foo1["float"](h)
# fails
ROOT.foo2["float"](h)
# works
ROOT.foo2["float"](ax)
# fails
ROOT.foo1["float"](ax)


Hi @AlkaidCheng,

Thanks for reporting this. Indeed, it seems that cppyy sees two overloads, but both have the same prototype:

  none of the 2 overloaded methods succeeded. Full details:
  float ::foo2(TAxis* h) =>
    TypeError: could not convert argument 1
  float ::foo2(TAxis* h) =>
    TypeError: could not convert argument 1

The same example works in cling at the ROOT prompt. Any ideas @etejedor?

Cheers,
J.

This looks like a bug, I’ll open a ticket.

This is now [PyROOT] Error when looking for function template overload · Issue #10224 · root-project/root · GitHub , thank you for reporting!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.