@@ -125,10 +125,15 @@ The error conditions that can arise, and their defined results, are as
125
125
follows. The intention is that the defined results are the same as the
126
126
defined results today. The only change is that now a panic may result.
127
127
128
- - The operations ` + ` , ` - ` , ` * ` , ` / ` , ` % ` can underflow and
129
- overflow.
130
- - Shift operations (` << ` , ` >> ` ) can shift a value of width ` N ` by more
131
- than ` N ` bits.
128
+ - The operations ` + ` , ` - ` , ` * ` , can underflow and overflow. When checking is
129
+ enabled this will panic. When checking is disabled this will two's complement
130
+ wrap.
131
+ - The operations ` / ` , ` % ` for the arguments ` INT_MIN ` and ` -1 `
132
+ will unconditionally panic. This is unconditional for legacy reasons.
133
+ - Shift operations (` << ` , ` >> ` ) on a value of with ` N ` can be passed a shift value
134
+ > = ` N ` . It is unclear what behaviour should result from this, so the shift value
135
+ is unconditionally masked to be modulo ` N ` to ensure that the argument is always
136
+ in range.
132
137
133
138
## Enabling overflow checking
134
139
@@ -145,7 +150,7 @@ potential overflow (and, in particular, for code where overflow is
145
150
expected and normal, they will be immediately guided to use the
146
151
wrapping methods introduced below). However, because these checks will
147
152
be compiled out whenever an optimized build is produced, final code
148
- wilil not pay a performance penalty.
153
+ will not pay a performance penalty.
149
154
150
155
In the future, we may add additional means to control when overflow is
151
156
checked, such as scoped attributes or a global, independent
@@ -451,17 +456,7 @@ were:
451
456
452
457
# Unresolved questions
453
458
454
- The C semantics of wrapping operations in some cases are undefined:
455
-
456
- - ` INT_MIN / -1 ` , ` INT_MIN % -1 `
457
- - Shifts by an excessive number of bits
458
-
459
- This RFC takes no position on the correct semantics of these
460
- operations, simply preserving the existing semantics. However, it may
461
- be worth trying to define the wrapping semantics of these operations
462
- in a portable way, even if that implies some runtime cost. Since these
463
- are all error conditions, this is an orthogonal topic to the matter of
464
- overflow.
459
+ None today (see Updates section below).
465
460
466
461
# Future work
467
462
@@ -491,6 +486,10 @@ Since it was accepted, the RFC has been updated as follows:
491
486
2 . ` as ` was changed to restore the behavior before the RFC (that is,
492
487
it truncates to the target bitwidth and reinterprets the highest
493
488
order bit, a.k.a. sign-bit, as necessary, as a C cast would).
489
+ 3 . Shifts were specified to mask off the bits of over-long shifts.
490
+ 4 . Overflow was specified to be two's complement wrapping (this was mostly
491
+ a clarification).
492
+ 5 . ` INT_MIN / -1 ` and ` INT_MIN % -1 ` panics.
494
493
495
494
# Acknowledgements and further reading
496
495
0 commit comments