<numeric>: check for gcd / lcm overflows#4776
<numeric>: check for gcd / lcm overflows#4776StephanTLavavej merged 14 commits intomicrosoft:mainfrom
<numeric>: check for gcd / lcm overflows#4776Conversation
In compile time or in debug. Applies to C++20 and later mode.
`_Mul_overflow` is made to only handle non-`bool` integer types in C++17.
Backport overflow checking of `lcm`/`gcd` to C++17
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
numeric: Add a `static_cast` when dividing `_Common_unsigned` by `_Common_unsigned`, due to the usual arithmetic conversions which will emit sign conversion warnings for tiny types. utility: * Move `_Is_standard_integer` down to the `_HAS_CXX20` region. (It's also used by `<mdspan>`.) * Relax the internal `_Cmp_equal`, `_Cmp_less`, and `_In_range` to accept nonbool integrals. + Because they're internal, we can `_STL_INTERNAL_STATIC_ASSERT`. + Comment that this "allows character types". * Enforce `_Is_standard_integer` at the user-visible layer. P0295R0_gcd_lcm: Add test coverage, because gcd/lcm are required to accept nonbool integrals. (An MSVC-internal test found this by using `char`.)
|
I pushed a commit: Fix gcd/lcm to work with all nonbool integrals. numeric: Add a utility:
P0295R0_gcd_lcm: Add test coverage, because gcd/lcm are required to accept nonbool integrals. (An MSVC-internal test found this by using |
|
|
||
| #if _HAS_CXX20 | ||
| template <class _Ty> | ||
| constexpr bool _Is_standard_integer = _Is_any_of_v<remove_cv_t<_Ty>, signed char, short, int, long, long long, |
There was a problem hiding this comment.
Could be useful to comment that this can be used to test for standard and extended integer types, because there are no extended integer types (probably in a subsequent change)
|
Thanks for implementing these checks! My internal branch was |
In compile time or in debug.
Fixes #2300