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

clang-20 - compilation error 😢 #1311

Closed
alexv-ds opened this issue Aug 17, 2024 · 3 comments
Closed

clang-20 - compilation error 😢 #1311

alexv-ds opened this issue Aug 17, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@alexv-ds
Copy link
Contributor

Describe the bug
Compilation error

addons/cpp/utils/enum.hpp:240:33: error: no matching function for call to 'to_int'

To Reproduce
Steps to reproduce the behavior:

  1. Get sample.zip
  2. Compile it

Additional context
tested on - clang-20, ubuntu-24.04

@alexv-ds alexv-ds added the bug Something isn't working label Aug 17, 2024
@apache-hb
Copy link
Contributor

apache-hb commented Sep 22, 2024

I've also hit this and have a bit more context as to why this has become an issue.

to_int casts an integer to an enum value, clang incorrectly used to allow any integer value to be cast to an enum value at compile time, since 20 clang now refuses to instantiate enum values at compile time with a value not in the representable bit range of enum values. C++ (since 20?) specifies that enums are at least as large as the minimum number of bits required to represent all values in 2s complement.

This means its no longer enough to use FLECS_ENUM_MAX(E) as an upper bound, some other way will need to be used to prevent going out of range. std::numeric_limits<std::underlying_type_t<E>> won't be enough because it'll round up to the nearest 8 bits, and even going 1 bit out of range triggers this compiler error.

@SanderMertens
Copy link
Owner

magic_enum ran into the same issue, this looks like a potential fix:
https://github.com/Neargye/magic_enum/blob/master/include/magic_enum/magic_enum.hpp#L626

@SanderMertens
Copy link
Owner

Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants