2 ms·
The parent spoke a bit too broadly. Here’s the rules: * overflow is a “program error”, not UB * compilers must either check for overflow and panic, or two’s c
by steveklabnik 8y ago
The parent spoke a bit too broadly. Here’s the rules:
* overflow is a “program error”, not UB
* compilers must either check for overflow and panic, or two’s compliment wrap
* when debug_assertions are on, implementations are required to panic on overflow
This means release mode wraps today, but if it’s cheap enough someday, we could make it panic.
If you want specific semantics on overflow, then you should use the various wrappers and/or methods that let you do them directly, rather than relying on any of the above. But you don’t have to specify; by default, the above is the semantics.
- Paul-ish 8y agoWhat if rust got "unchecked" (unsafe) versions of arithmetic operations that have C arithmetic semantics. Kind of the opposite of "checked_add".
- steveklabnik 8y agoIt’s possible! Nobody has ever proposed it...