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

Fix warnings in enum.hpp high bit calculation #1509

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jpeletier
Copy link
Contributor

This PR fixes compilation warnings, at least in GCC, due to sign mismatch calculating high_bit in enum.hpp

After #696 was merged, a warning appeared when compiling enum.hpp:

/flecs/private/../addons/cpp/utils/enum.hpp:264:49: warning: overflow in conversion from ‘int’ to ‘flecs::_::enum_reflection<Ei8, flecs::_::enum_data_impl<Ei8>::reflection_count>::U’ {aka ‘signed char’} changes value from ‘128’ to ‘-128’ [-Woverflow]
  264 |     static const U high_bit = static_cast<U>(1) << (sizeof(U) * 8 - 1);

Inspite of the warning, the code works. The PR fixes this issue by calculating the high bit with an unsigned version, then casting back to the underlying enum type. This tells the compiler we really mean what we are doing.

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

Successfully merging this pull request may close these issues.

1 participant