News for hackers. Stuff that matters.
Re:C++ needs undefined behavior, but maybe less by MaxBarraclough on Monday November 27, 2023 @04:31PM (#38438653)
As others have pointed out, compilers are already free to do that if they wish. GCC has a flag to trap on signed integer overflow, [0] I believe Clang does too.

Another option is to use a library like SafeInt [1] or Boost Safe Numerics [2] which offer drop-in replacement types like safe<int>. If you want to use raw unchecked integer types in release builds, you could do that using a typedef like my_int, in combination with a #if.

[0] https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html , the -ftrapv flag

[1] https://github.com/dcleblanc/SafeInt

[2] https://www.boost.org/doc/libs/release/libs/safe_numerics/do...

There are no comments on this comment yet.