-
Notifications
You must be signed in to change notification settings - Fork 483
Fix EnumFlags compilation for large enums #14650
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
Conversation
|
REQUEST FOR PRODUCTION RELEASES: This will add The following labels are available |
|
@f3sch could you please have a look at the proposed change? I could not figure out any side effect, but I am not really an expert of this part of the code. I would need this PR to be able to use the EnumFlags to handle the RCT selection flags in O2Physics, where we have an enum with 32 elements (one for each of the 32 bits in the RCT mask). Thanks! |
|
send suggestions via private channel. |
The EnumFlags fails to compile when the underlying enum has 30 or more elements.
With exactly 32 elements the compilation error is the following:
note: shift count 32 >= width of type 'int' (32 bits)
static constexpr auto MaxRep{((1 << (Max_u_v - Min_u_v + 1)) - 1) << Min_u_v}; // largest representable value
With 30 or 31 elements the compilation error is:
note: value -2147483649 is outside the range of representable values of type 'int'
static constexpr auto MaxRep{((1 << (Max_u_v - Min_u_v + 1)) - 1) << Min_u_v}; // largest representable value
The solution consists in using "1ULL" literals in the MaxRep expression, such that the bit shifts are
performed on a variable with at least 64-bits.
d97417b to
385e60b
Compare
|
@f3sch could you please check the updated commit? Thanks! |
|
@aferrero2707 did it change from what I sent you? |
|
No, a priori is exactly your patch... |
|
ah, ok :) LGTM! |
|
@sawenzel all CIs are green... would you have the time to have a look? This PR is needed to finalise some work on the RTC selection flags in O2Physics. Thanks! |
The EnumFlags fails to compile when the underlying enum has 30 or more elements.
With exactly 32 elements the compilation error is the following:
With 30 or 31 elements the compilation error is:
The solution consists in casting to unint64_t the first "1" in the MaxRep expression, such that the bit shifts are performed on a 64-bit variable.