Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] enum class initializer throws NameError #5638

Closed
vyasr opened this issue Aug 21, 2023 · 1 comment · Fixed by #5642
Closed

[BUG] enum class initializer throws NameError #5638

vyasr opened this issue Aug 21, 2023 · 1 comment · Fixed by #5642
Milestone

Comments

@vyasr
Copy link
Contributor

vyasr commented Aug 21, 2023

Describe the bug

In C++ initialization of an enum class should value initialize (at least in the case of an empty initializer list, I haven't dug too deeply into what should happen if given a real value). Cython compiles such code but then throws a NameError at runtime.

Code to reproduce the behaviour:

# distutils: language = c++


cdef enum class my_enum(int):
    a = 1
    b = 2


def f():
    my_enum()

This code compiles correctly, but at runtime I get:

(main) dt08% python -c 'import definitions; definitions.f()'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "definitions.pyx", line 10, in definitions.f
    my_enum()
NameError: name 'my_enum' is not defined

Expected behaviour

I think throwing an error during compilation would be an acceptable outcome here, if normal value initialization is not possible (especially if the non-empty initializer list case is actually UB; I haven't looked deeply enough yet to say either way).

OS

Linux

Python version

3.11.4

Cython version

3.0.0

Additional context

No response

@vyasr
Copy link
Contributor Author

vyasr commented Aug 21, 2023

CC @shwina

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants