[Patch] Fix libstdc++/11400

Martin Sebor sebor@roguewave.com
Mon Sep 29 19:45:00 GMT 2003


Paolo Carlini wrote:

> Hi,
> 
> the below, privately suggested by Nathan, is a minimal fix for the PR.
> Seems the correct approach to me too! In fact 
> iterator_traits<>difference_type
> is already used elsewhere in the same file for counting.
> 
> Tested x86-linux. Ok with everyone?

FWIW, this is still not 100% correct. __count - 1 is not guaranteed
to be defined or to return a type that's convertible to int. Imagine

     struct Integral {
         void operator- (int) { }
     };

A safer fix would be to first convert __count to some integer type
and then decrement the copy:

     typename iterator_traits<_ForwardIterator>::difference_type
         __n = __count;
     --__n;

Regards
Martin




More information about the Libstdc++ mailing list