mirror of git://gcc.gnu.org/git/gcc.git
Simplify overflow checks in duration literals
* include/std/chrono (__check_overflow): Simplify definition. (_Checked_integral_constant): Remove. From-SVN: r263537
This commit is contained in:
parent
26e130482e
commit
b8b5398cbd
|
|
@ -1,5 +1,8 @@
|
||||||
2018-08-14 Jonathan Wakely <jwakely@redhat.com>
|
2018-08-14 Jonathan Wakely <jwakely@redhat.com>
|
||||||
|
|
||||||
|
* include/std/chrono (__check_overflow): Simplify definition.
|
||||||
|
(_Checked_integral_constant): Remove.
|
||||||
|
|
||||||
PR libstdc++/86846
|
PR libstdc++/86846
|
||||||
* src/c++17/default_resource.h: New file, defining default_res.
|
* src/c++17/default_resource.h: New file, defining default_res.
|
||||||
* src/c++17/memory_resource.cc [ATOMIC_POINTER_LOCK_FREE != 2]
|
* src/c++17/memory_resource.cc [ATOMIC_POINTER_LOCK_FREE != 2]
|
||||||
|
|
|
||||||
|
|
@ -900,24 +900,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|
||||||
{
|
{
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wliteral-suffix"
|
#pragma GCC diagnostic ignored "-Wliteral-suffix"
|
||||||
template<typename _Rep, unsigned long long _Val>
|
|
||||||
struct _Checked_integral_constant
|
|
||||||
: integral_constant<_Rep, static_cast<_Rep>(_Val)>
|
|
||||||
{
|
|
||||||
static_assert(_Checked_integral_constant::value >= 0
|
|
||||||
&& _Checked_integral_constant::value == _Val,
|
|
||||||
"literal value cannot be represented by duration type");
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename _Dur, char... _Digits>
|
template<typename _Dur, char... _Digits>
|
||||||
constexpr _Dur __check_overflow()
|
constexpr _Dur __check_overflow()
|
||||||
{
|
{
|
||||||
using _Val = __parse_int::_Parse_int<_Digits...>;
|
using _Val = __parse_int::_Parse_int<_Digits...>;
|
||||||
using _Rep = typename _Dur::rep;
|
constexpr typename _Dur::rep __repval = _Val::value;
|
||||||
// TODO: should be simply integral_constant<_Rep, _Val::value>
|
static_assert(__repval >= 0 && __repval == _Val::value,
|
||||||
// but GCC doesn't reject narrowing conversions to _Rep.
|
"literal value cannot be represented by duration type");
|
||||||
using _CheckedVal = _Checked_integral_constant<_Rep, _Val::value>;
|
return _Dur(__repval);
|
||||||
return _Dur{_CheckedVal::value};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr chrono::duration<long double, ratio<3600,1>>
|
constexpr chrono::duration<long double, ratio<3600,1>>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue