diff --git a/bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx b/bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx index d37b04f26338e..9a9664c0d9a23 100644 --- a/bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx +++ b/bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx @@ -663,8 +663,8 @@ static PyObject* tpp_call(TemplateProxy* pytmpl, PyObject* args, PyObject* kwds) int pcnt = 0; pymeth = pytmpl->Instantiate(pytmpl->fTI->fCppName, args, nargsf, pref, &pcnt); if (pymeth) { - // attempt actual call; argument based, so do not allow implicit conversions - result = CallMethodImp(pytmpl, pymeth, args, nargsf, kwds, false, sighash); + // attempt actual call; even if argument based, allow implicit conversions, for example for non-template arguments + result = CallMethodImp(pytmpl, pymeth, args, nargsf, kwds, true, sighash); if (result) TPPCALL_RETURN; } Utility::FetchError(errors); diff --git a/bindings/pyroot/cppyy/cppyy/test/test_templates.py b/bindings/pyroot/cppyy/cppyy/test/test_templates.py index f679226e1cca1..7c2ea9bdfb53a 100644 --- a/bindings/pyroot/cppyy/cppyy/test/test_templates.py +++ b/bindings/pyroot/cppyy/cppyy/test/test_templates.py @@ -1184,6 +1184,29 @@ def test35_no_possible_cpp_name(self): with pytest.raises(TypeError, match=r"could not construct C\+\+ name"): cppyy.gbl.test35_func[set(), list()]() + def test36_constructor_implicit_conversion(self): + """Implicit conversion to call a templated constructor""" + + import cppyy + + cppyy.cppdef("""\ + namespace ConstructorImplicitConversion { + struct IntWrapper { + IntWrapper(int i) : m_i(i) {} + int m_i; + }; + struct S { + template + S(IntWrapper a, T b) : m_a(a.m_i) {} + + int m_a = 0; + }; }""") + + ns = cppyy.gbl.ConstructorImplicitConversion + + a = ns.S(1, 2) + assert a.m_a == 1 + class TestTEMPLATED_TYPEDEFS: def setup_class(cls):