parse_numbers.h (_Number_help): Fix divide-by-zero.

* 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.

From-SVN: r211890
This commit is contained in:
Jonathan Wakely 2014-06-23 12:30:32 +01:00 committed by Jonathan Wakely
parent 463036be82
commit 83387bbd28
4 changed files with 17 additions and 4 deletions

View File

@ -1,3 +1,10 @@
2014-06-23 Jonathan Wakely <jwakely@redhat.com>
* 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.
2014-06-18 Paolo Carlini <paolo.carlini@oracle.com>
Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>

View File

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

View File

@ -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");
};

View File

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