-
Notifications
You must be signed in to change notification settings - Fork 82
[MERGED] warning 24X: negative or too big shift count #539
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
What about right shifts? Also, a related suggestion would be a warning for this: enum A (<<= 1)
{
B = 1,
c00,
c01,
c02,
c03,
c04,
c05,
c06,
c07,
c08,
c09,
c10,
c11,
c12,
c13,
c14,
c15,
c16,
c17,
c18,
c19,
c20,
c21,
c22,
c23,
c24,
c25,
c26,
c27,
c28,
c29,
c30,
c31,
c32,
c33,
c34,
c35,
c36,
c37,
c38,
c39
} Where the enum shifts overflow. |
I wanted to do this initially, but currently the left shift in enum declarations is processed in the same way as multiplication (e.g.
But it does work on right shifts. |
Nice. |
Now `__emit` too uses warning 241 for `shl.c.pri/alt` and `shr.c.pri/alt`.
4dfb407
to
681fbdb
Compare
Updated this PR; now warning 24X is also printed when the specified left shift count is too big enum (<<= 32) // warning 24X: negative or too big shift count
{
// ...
}; |
Also, even though I incorporated the fix from #546, I haven't made warning 24X work for shift overflow in enum items yet, as I'm not sure if this warning is correct for such situations. enum (<<= 1)
{
c0 = 1,
c1,
c2,
/* ... */
c31,
c32, // overflow
}; In this example, technically, |
6f6d70a
to
0930977
Compare
…t be shown again for the next enum item. Also rename the variable into more descriptive "warn_overflow".
What this PR does / why we need it:
This PR allows the compiler to warn the user if the shift count is too big or negative (both of which are UB), as suggested in #528.
For example, this could be useful when the user tries to store too many bit flags into one variable:
Which issue(s) this PR fixes:
Fixes #
What kind of pull this is:
Additional Documentation: