<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 }})

AlexGuteniev

In compile time or in debug.

Fixes #2300

@AlexGuteniev

In compile time or in debug. Applies to C++20 and later mode.

AlexGuteniev

frederick-vs-ja

@frederick-vs-ja

_Mul_overflow is made to only handle non-bool integer types in C++17.

@AlexGuteniev

Backport overflow checking of lcm/gcd to C++17

@AlexGuteniev

@AlexGuteniev

@StephanTLavavej

@StephanTLavavej

@StephanTLavavej

@StephanTLavavej

StephanTLavavej

StephanTLavavej

@StephanTLavavej

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej

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:

P0295R0_gcd_lcm: Add test coverage, because gcd/lcm are required to accept nonbool integrals. (An MSVC-internal test found this by using char.)

@StephanTLavavej

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:

P0295R0_gcd_lcm: Add test coverage, because gcd/lcm are required to accept nonbool integrals. (An MSVC-internal test found this by using char.)

StephanTLavavej

AlexGuteniev

@@ -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)

@StephanTLavavej

Thanks for implementing these checks! My internal branch was dev/stl/least-common-meowtiple 😹 🧮 📈