cppyy icon indicating copy to clipboard operation
cppyy copied to clipboard

NotImplementedError with enum namespace

Open cgdae opened this issue 3 years ago • 3 comments

It looks like cppyy might not correctly handle the enum namespace.

This code:

import cppyy
cppyy.cppdef('''
        enum foo { FOO };
        void foo() {}
        void bar( enum foo f) {}
        ''')
cppyy.gbl.bar( cppyy.gbl.FOO)

- results in:

NotImplementedError: void ::bar(enum foo f) =>
    NotImplementedError: could not convert argument 1 (this method cannot (yet) be called)

Removing the void foo() {} function makes things work, so is cppyy/cling being confused by the difference between enum foo and foo?

[Unfortunately the code i'm attempting to wrap with cppyy has exactly this pattern where a function has the same name as an enum.]

Thanks for any help. And for cppyy.

cgdae avatar Apr 05 '22 16:04 cgdae

Well now, I didn't even know one could do that. :) Anyway, this particular case is now fixed in repo (cppyy-backend and cppyy-cling).

However, there are some variations on this theme and these still need fixing:

template<enum foo>
struct BarT {};

and:

 enum class Foo : int8_t { FOO };
 void Foo() {}
 void bar(enum Foo) {}

The former is a lookup problem in Cling (I think); the second is a genuine mess as it then needs cppyy.gbl.Foo.FOO, but cppyy.gbl.Foo is found as that function (probably the most useful) and it's not really possible to use the same name for two different things. Should then either use a conventional enum_Foo (very inconvenient b/c the function could be added after the fact, changing the behavior of the enum) or add the enums to the function (is harmless when not used; and clear when it is).

I'm placing both on low priority until someone comes up with an actual use case. :)

wlav avatar Apr 07 '22 21:04 wlav

Thanks for the fix, will try it soon hopefully.

This is the only time i've ever seen anything like enum class Foo : int8_t { FOO };. Thankfully i don't have any code like that to wrap, so i'm happy for it to be low priority :-)

Thanks,

- Jules

cgdae avatar Apr 25 '22 14:04 cgdae

Fix to the original problem is released with 2.4.0 and its dependencies. Leaving this open for the other varietals.

wlav avatar Jun 30 '22 17:06 wlav