_Safe_add checks for overflow but does not do anything to report the problem!


Looking at VC++ source files I find in ratio the following:

what is the purpose of _Safe_add_integer_arithmetic_overflow_error?



1
2
3
4
5
6
7
8
9
inline void _Safe_add_integer_arithmetic_overflow_error() noexcept {}

_NODISCARD constexpr intmax_t _Safe_add(const intmax_t _Ax, const intmax_t _Bx) noexcept {
    if (_Sign_of(_Ax) == _Sign_of(_Bx) && _Abs(_Ax) > INTMAX_MAX - _Abs(_Bx)) {
        _Safe_add_integer_arithmetic_overflow_error();
    }

    return _Ax + _Bx;
}


How does calling this void function alert us that there would be overflow?

Registered users can post here. Sign in or register to post.