This is the mail archive of the
mailing list for the libstdc++ project.
Re: vector lightweight debug mode
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: FranÃois Dumont <frs dot dumont at gmail dot com>
- Cc: Jonathan Wakely <jwakely at redhat 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: Sat, 19 Sep 2015 10:12:21 +0100
- Subject: Re: 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> <55FD0F35 dot 4010106 at gmail dot com>
On 19 September 2015 at 08:31, FranÃois Dumont wrote:
> On 16/09/2015 22:29, Jonathan Wakely wrote:
>> No, because it is undefined to compare iterators that belong to
>> different containers, or to compare pointers that point to different
> (Written before Christopher reply:)
> At least program will compile only if iterator is coming from a vector
> of the same type. So behavior is undefined only if user pass an invalid
> iterator which is exactly what this check tries to detect, isn't it
> paradoxical ? If this undefined behavior results in the program abortion
> this is what should happen anyway. If it doesn't abort then the program
> will definitely not behaves as expected so this check doesn't make
> anything worst, no ?
The problem is that undefined behaviour can "travel backwards in time".
It's not as simple as saying that if the invalid check happens _then_
undefined behaviour happens afterwards.
However, Google seem to find these checks useful, and you and Chris
are in favour, so let's keep them.