This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] Fix libstdc++/11400


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]