PR 57779 New debug check
François Dumont
frs.dumont@gmail.com
Thu Jul 11 20:16:00 GMT 2013
On 07/11/2013 06:58 PM, Jonathan Wakely wrote:
> On 11 July 2013 17:43, Paolo Carlini wrote:
>>> + if (&(*(__it._M_get_sequence()->_M_base().end()))
>>>
>>> Isn't this a dereference of a non-dereferenceable iterator?
>> Looks like this function does a very tricky work! I think that at least we
>> should use __addressof and std::less, std::greater, etc to compare pointers.
>> In general, we should probably try to be conservative in the first
>> implementation of the check, act only when we *really* know we have
>> contiguous memory, not even "blocks", like for std::deque.
> The safest way would probably be to add an __is_contiguous trait,
> specialized for the __gnu_debug versions of vector, array, and
> dynarray, then check __is_contiguous<_Sequence>.
>
IMO the current check is enough. Of course it will consider a
std::deque with only 1 block as continuous memory, and so what ? Passing
a pointer to those continuous elements is bad and will be detected then.
As soon as std::deque elements will be split in at least 2 blocks the
check won't be performed anymore but it doesn't make the check useless.
It would be worst if the check was generating false positive results.
I am indeed dereferencing the end iterator but as long as it is
just to get the address of the resulting element it is fine. However
that's a good remark cause I never realized that getting the address of
this invalid iterator is in fact giving a correct result. But the
Standard is saying that we shall assert in debug mode so it is fine.
François
More information about the Libstdc++
mailing list