<numeric>
: check for gcd / lcm overflows by AlexGuteniev · Pull Request #4776 · microsoft/STL (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation20 Commits14 Checks39 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
In compile time or in debug.
Fixes #2300
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".
- Because they're internal, we can
- 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 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".
- Because they're internal, we can
- 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
.)
@@ -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, |
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 dev/stl/least-common-meowtiple
😹 🧮 📈