commit c57e645222ac9bf476ef5b6414773b5f4e2b86fc
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Sun Jun 22 18:06:42 2014 +0100
* include/bits/parse_numbers.h (_Number_help): Fix divide-by-zero.
* include/std/chrono (_Checked_integral_constant): Allow zero.
* testsuite/20_util/duration/literals/values.cc: Test non-positive
values and digit separators.
@@ -190,10 +190,11 @@ namespace __parse_int
using __digit = _Digit<_Base, _Dig>;
using __valid_digit = typename __digit::__valid;
using __next = _Number_help<_Base,
- _Pow / (_Base * __valid_digit::value),
+ __valid_digit::value ? _Pow / _Base : _Pow,
_Digs...>;
using type = __ull_constant<_Pow * __digit::value + __next::type::value>;
- static_assert((type::value / _Pow) == __digit::value, "overflow");
+ static_assert((type::value / _Pow) == __digit::value,
+ "integer literal does not fit in unsigned long long");
};
template<unsigned _Base, unsigned long long _Pow, char _Dig>
@@ -214,7 +215,6 @@ namespace __parse_int
{ };
//------------------------------------------------------------------------------
-// This _Parse_int is the same 'level' as the old _Base_dispatch.
template<char... _Digs>
struct _Parse_int;
@@ -791,7 +791,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
struct _Checked_integral_constant
: integral_constant<_Rep, static_cast<_Rep>(_Val)>
{
- static_assert(_Checked_integral_constant::value > 0
+ static_assert(_Checked_integral_constant::value >= 0
&& _Checked_integral_constant::value == _Val,
"literal value cannot be represented by duration type");
};
@@ -56,6 +56,12 @@ test03()
VERIFY( workday == std::chrono::hours(8) );
auto fworkday = 8.0h;
VERIFY( (fworkday == std::chrono::duration<long double, std::ratio<3600,1>>(8.0L)) );
+ auto immediate = 0s;
+ VERIFY( immediate == std::chrono::seconds(0) );
+ auto minute_ago = -1min;
+ VERIFY( minute_ago == std::chrono::minutes(-1) );
+ auto separated = 1'000'000s;
+ VERIFY( separated == std::chrono::seconds(1'000'000) );
}
int