cppyy
cppyy copied to clipboard
Cppyy doesn't recognize explicitly instantiated template when the template is a custom enum
Platform into:
- MacOS 14.1.1 (arm64-apple-darwin23.1.0)
- clang version 18.1.8
- Python 3.11
- cppyy 3.1.2
Here's a minimal example test.cpp file for reproduction:
template<int T>
class IntTemplate {
public:
void doSomethingInt();
};
template<> void IntTemplate<0>::doSomethingInt() {}
template class IntTemplate<0>;
enum class DemoEnum {
A,
};
template<DemoEnum T>
class EnumTemplate {
public:
void doSomethingEnum();
};
template<> void EnumTemplate<DemoEnum::A>::doSomethingEnum() {}
template class EnumTemplate<DemoEnum::A>;
Compile with clang++ -dynamiclib -o libtest.dylib test.cpp and run the following python code:
import cppyy
cppyy.include('test.cpp')
cppyy.load_library('test.dylib')
from cppyy.gbl import IntTemplate, EnumTemplate, DemoEnum
IntTemplate[0]() # this works
EnumTemplate[DemoEnum.A]()
Instantiating the IntTemplate works, but instantiating the EnumTemplate throws an error:
Traceback (most recent call last):
File "/[...]/test.py", line 8, in <module>
EnumTemplate[DemoEnum.A]()
~~~~~~~~~~~~^^^^^^^^^^^^
File "[...]/python3.11/site-packages/cppyy/_cpython_cppyy.py", line 88, in __getitem__
pyclass = _backend.MakeCppTemplateClass(*newargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'EnumTemplate<A>' is not a known C++ class