[PATCH, libstdc++/61166] overflow when parse number in std::duration operator""

Jonathan Wakely jwakely@redhat.com
Wed May 14 15:36:00 GMT 2014

On 14/05/14 15:41 +0100, Jonathan Wakely wrote:
>On 14 May 2014 15:36, Jonathan Wakely wrote:
>> On 14 May 2014 15:25, Ed Smith-Rowland wrote:
>>> But in keeping with, say, our extension type traits and such maybe i should
>>> uglify value as well.
>> No, just derive from std::integral_constant and you get value "for free".
>> You already use integral_constant in that file, so the name "value" is
>> already used.
>That also has the advantage that _Digit<B, 'f'> and _Digit<B, 'F'>
>share the same base class, so you don't end up with two different
>static members with the same value (and if you make __valid a typedef
>as I suggested you don't have any static members for that either).

I've attached a first pass at doing it that way, using
integral_constant base classes and working with types not values as
much as possible. This gets rid of all static const members except in
_Digits<> (where is that used?)

>Do we really need _Digit::value to be unsigned long long, or is it
>only the results in _Power_help and _Number_help that need to be

Because I made _Digit derive from integral_constant<unsigned> that
means the partial specialization of _Number_help for single digits has
_Number_help::type as integral_constant<unsigned>, where the other
specializations have integral_constant<unsigned long long>. That's
inconsistent, but works. Maybe we'd want to be consistent though, and
use this instead of typename _Digit<Base, _Dig>::type:

  using type = integral_constant<unsigned long long,
                                 _Digit<_Base, _Dig>::value>;

(Also, I wonder if we could use std::ratio for the power/base
arithmetic, but it might not help.)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 11414 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20140514/989078ab/attachment.bin>

More information about the Libstdc++ mailing list