This is the mail archive of the
mailing list for the libstdc++ project.
Fwd: vector lightweight debug mode
- From: Christopher Jefferson <chris at bubblescope dot net>
- To: FranÃois Dumont <frs dot dumont at gmail dot com>, "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 17 Sep 2015 21:52:11 +0100
- Subject: Fwd: vector lightweight debug mode
- Authentication-results: sourceware.org; auth=none
- References: <55F71189 dot 8080006 at gmail dot com> <20150914195038 dot GQ2631 at redhat dot com> <55F9C4F6 dot 6030706 at gmail dot com> <20150916202953 dot GE2631 at redhat dot com> <CA+jCFLueUi0Zo4m2D-scXNG5JLVSObKbJgXWaQRJrQ+notbXzg at mail dot gmail dot com>
---------- Forwarded message ----------
From: Christopher Jefferson <firstname.lastname@example.org>
Date: 17 September 2015 at 18:59
Subject: Re: vector lightweight debug mode
To: Jonathan Wakely <email@example.com>
On 16 September 2015 at 21:29, Jonathan Wakely <firstname.lastname@example.org> wrote:
> On 16/09/15 21:37 +0200, FranÃois Dumont wrote:
>>>> @@ -1051,6 +1071,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
>>>> insert(const_iterator __position, size_type __n, const
>>>> value_type& __x)
>>>> + __glibcxx_assert(__position >= cbegin() && __position <= cend());
>>>> difference_type __offset = __position - cbegin();
>>>> _M_fill_insert(begin() + __offset, __n, __x);
>>>> return begin() + __offset;
>>> This is undefined behaviour, so I'd rather not add this check (I know
>>> it's on the google branch, but it's still undefined behaviour).
>> Why ? Because of the >= operator usage ? Is the attached patch better ?
>> < and == operators are well defined for a random access iterator, no ?
> No, because it is undefined to compare iterators that belong to
> different containers, or to compare pointers that point to different
While that's true, on the other hand it's defined behaviour when the
assert passes, and in the case where the thing it's trying to check
fails, we are off into undefined-land anyway.
A defined check would be to check if __offset is < 0 or > size(). Once
again if it's false we are undefined, but the assert line itself is
then defined behaviour.