On Tuesday 06 September 2011 23:09:17, Jonathan Wakely wrote:
> On 6 September 2011 22:58, Paul Pluzhnikov wrote:
> > On Tue, Sep 6, 2011 at 2:51 PM, Jonathan Wakely <jwakely....@gmail.com> 
> > wrote:
> >
> >> I don't mean for vector::begin and the other functions in that patch,
> >> I mean in general for member functions of any type. There are plenty
> >> of functions that wouldn't crash when called through a null pointer.
> >> But even std:vector has member functions like that, such as max_size.
> >
> > Right. (We might tweak the compiler to automagically insert that assert
> > in non-omitimized builds ;-)
> 
> Heh :-)
> 
> Have you considered a compiler option to make 'delete v' zero out the
> pointer, so that any following use of it gives an immediate segfault?
> That would be conforming (the value of delete's operand is unspecified
> after the operation), but would only help if the same pointer is used,
> rather than another object with the same value.  I don't know of any
> compiler that does that, but have wondered if it would be useful for
> debugging some cases.

Zeroing out would hide bugs; there's lots of code that does 

delete ptr;
...
...
...

if (ptr)
 {
   ptr->...
 }

You'd not see the bug that way.  Making 'delete v' clobber the pointer
with 0xdeadbeef or ~0 instead would be better.

-- 
Pedro Alves

Reply via email to