root icon indicating copy to clipboard operation
root copied to clipboard

PyROOT doesn't work with templated binary operator implementations like `operator+`

Open guitargeek opened this issue 1 year ago • 0 comments

Description

Operators like operator+ don't work in cppyy if they are implemented as template functions.

Reproducer

import cppyy

cppyy.cppdef("""

template<class T>
struct Foo {
    Foo(T v) : val{v} {}
    T val;
};

template <class T>
Foo<T> operator+(Foo<T> const &a, Foo<T> const &b)
{
   return Foo<T>{a.val + b.val};
}

""")

klass = cppyy.gbl.Foo["int"]

a = klass(4)
b = klass(7)

a + b

ROOT version

At least ROOT 6.04 according to original Jira ticket: https://its.cern.ch/jira/browse/ROOT-7717

Installation method

Build master from source

Operating system

Arch Linux

Additional context

  • same problem as reported in ROOT-7717, but with a simplified reproducer
  • reproducer works with upstream cppyy, so the problem is likely related to the cppyy-backend (e.g. ROOT meta or CallFunc)

guitargeek avatar Apr 29 '24 13:04 guitargeek