[v3] libstdc++/44413 (for ext/vstring)

Doug Semler dougsemler@gmail.com
Thu Jun 10 15:03:00 GMT 2010


On Thu, Jun 10, 2010 at 10:51 AM, Paolo Carlini <pcarlini@gmail.com> wrote:
> On 06/10/2010 04:50 PM, Paolo Carlini wrote:
>> ... and by the way, this is triggering implementation defined behavior
>> again, because on 64-bit machines ptrdiff_t is of course 64 bits wide
>> and int is 32 bits.
>
> Disregard this. I'm too concentrated on other issues. Really, this is an
> optimization issue. Formally, anyway, you would use difference_type.
>

Yes, I'll check mainline when I get a chance and move the question
about the potential miss to gcc list if it's there.

(and actually the code that I would have suggested was (I had just put
something together quickly so that I could just compile the function).

difference_type __d = __n1 - __n2;
 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
   __d =  __gnu_cxx::__numeric_traits<int>::__max;
 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
   __d =  __gnu_cxx::__numeric_traits<int>::__min;

 return int(__d);

Which I don't see is any more "implentation defined" as the current
code, since the current code does the same thing behavior-wise
clamping the value.

Thanks,
Doug.



More information about the Libstdc++ mailing list