-
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
<ratio>
: Use constexpr
functions instead of TMPs
#2450
<ratio>
: Use constexpr
functions instead of TMPs
#2450
Conversation
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.
The final stretch...
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.
Some small nits
Regarding the |
Closing this PR because the use of TMPs was to implement LWG-2094, which makes overflow a SFINAE error instead of emitting diagnostics. There is no way to achieve the same thing with |
|
Since it is not required to be used for SFINAE, it can be made into a function, and a non-constexpr function can be called when overflow errors, triggering compiler error.
|
||
template <intmax_t _Ax, intmax_t _Bx, bool _Good, bool _Also_good> | ||
struct _Safe_addX : integral_constant<intmax_t, _Ax + _Bx> {}; // computes _Ax + _Bx without overflow | ||
inline void _Safe_add_integer_arithmetic_overflow_error() noexcept {} |
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.
Maybe comment as intentionally empty and not constexpr
?
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.
Maybe call abort()
to make is safe for runtime too?
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.
Actually never mind, as it is ready to merge.
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.
Same pattern as:
Line 175 in 59a87cc
inline void _You_see_this_error_because_arg_id_is_out_of_range() noexcept {} |
I'd be fine with commenting this pattern with // intentionally not constexpr
in the future, although I agree that it isn't worth resetting testing here. However, calling abort()
seems excessive, and then I'd worry about the compiler actually emitting codegen for functions that aren't going to be called.
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for using modern |
Fixes #2291
Blocked on https://developercommunity.visualstudio.com/t/1202945Why not make
_Gcd
a copy ofstd::gcd
?std::gcd
includes large headers such as<xutility>
and<limits>
. I did not dare try to make a new header (<xratio>
?) because I was not 100% sure if I can do it correctly.The callers of
_Gcd
only work withintmax_t
, so I figured it is easier to just update_Gcd
and its callers rather than worrying about making a new header.