Re:Understanding Integer Overflow in C/C++ (2012) [pdf]
by the_why_of_y on Monday July 11, 2016 @06:07PM
(#12075160)
You're right, there does not appear to be a way to achieve 1.
Rust arithmetic does 3. in debug builds, or something vaguely similar if requested by using the checked_* functions, and 2. in release builds, or if requested by using the wrapping_* functions, and 4. by using the saturating_* functions.
Recommended reading:
http://huonw.github.io/blog/2016/04/myths-and-legends-about-...
1. default - fail the compile if an overflow could happen
2. wrap - like gcc's -fwrapv option, and C's unsigned type
3. trap - like gcc's -ftrapv option
4. saturate - common DSP behavior
5. unsafe - like gcc's C signed integer cruelty (fastest code)
Eh, is it too late to add this? For compatibility with old code, there could be a compiler option to override the default behavior for a whole source file.