-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Should C-style enums silently overflow? #23030
Comments
triage: I-nominated (I suggest P-backcompat-lang, I-needs-decision.) |
@nrc is it by design that highfive responded to the above comment by assigning the 1.0 beta milestone? |
Hmm, no it is not, I guess it tried to find the milestone "I suggest P-backcompat-lang, I-needs-decision.", but I have no idea how it ended up with "1.0 beta". I'll look into it (also, I'll only check inside parens on the same line |
1.0 beta, P-backcompat-lang. |
Is this the same as #23235? |
@theemathas I'd say they are duplicates, except that this bug (I think) is a little more general. |
So, we do check for overflow in one case, namely for an overflow from (This ends up being treated as equivalent to That check is done here in ty.rs I'm going to try to generalize it to handle the specific repr's properly. (That will hopefully help fix #23221.) |
cc #23897 |
…values. Moved such overflow checking into one place (in `rustc::middle::ty`, since it needs to be run on-demand during `const_eval` in some scenarios), and revised `rustc_typeck` accordingly. (Note that we only check for overflow if program did not provide a discriminant value explicitly.) Fix rust-lang#23030 Fix rust-lang#23221 Fix rust-lang#23235
…values. Moved such overflow checking into one place (in `rustc::middle::ty`, since it needs to be run on-demand during `const_eval` in some scenarios), and revised `rustc_typeck` accordingly. (Note that we only check for overflow if program did not provide a discriminant value explicitly.) Fix rust-lang#23030 Fix rust-lang#23221 Fix rust-lang#23235
const_eval : add overflow-checking for {`+`, `-`, `*`, `/`, `<<`, `>>`}. One tricky detail here: There is some duplication of labor between `rustc::middle::const_eval` and `rustc_trans::trans::consts`. It might be good to explore ways to try to factor out the common structure to the two passes (by abstracting over the particular value-representation used in the compile-time interpreter). ---- Update: Rebased atop rust-lang#23841 Fix rust-lang#22531 Fix rust-lang#23030 Fix rust-lang#23221 Fix rust-lang#23235
Spawned off of a note from PR #22532 on commit 1246d40
The following program:
compiles and prints:
My personal preference would be for a compiler error due to the implicit overflow, with a note saying that the programmer should explicitly assign some value to
Foo::B
. (And thus they can opt into the current behavior by assigning itB = 0,
; thenFoo::C
would continue to be assigned 1 as today.)The text was updated successfully, but these errors were encountered: