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: vector lightweight debug mode


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
>> arrays.
>>
>
> (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.


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