-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<numeric>
: check for gcd / lcm overflows
#4776
Conversation
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 |
@@ -883,38 +876,56 @@ _NODISCARD constexpr bool _In_range(const _Ty _Value) noexcept { | |||
} | |||
|
|||
#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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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