Negative

Sean Kelly sean at f4.ca
Tue Feb 28 10:40:07 PST 2006


Walter Bright wrote:
> "Sean Kelly" <sean at f4.ca> wrote in message 
> news:du225a$2549$1 at digitaldaemon.com...
>>>> But
>>>> Transaction abc()
>>>> {
>>>>    try {
>>>>      Foo f = dofoo();
>>>>      Bar b = dobar();
>>>>      Def d = dodef();
>>>>      return Transaction(f, b, d);
>>>>   } catch(object er) {
>>>>        delete f; delete b; delete d;
>>>>   }
>>>> }
>>>> is not worse to be honest.
>>> It is worse because it won't even compile. f, b, and d are not in scope 
>>> in the catch statement. Even if they were, there's still a serious bug - 
>>> if dofoo() throws an exception, then the catch statement will attempt to 
>>> delete b and d, which are not even initialized yet.
>> Is it really a bug to call delete on a null reference?  This is 
>> well-defined behavior in C++.
> 
> It's not even a null reference. 

Not in the above example, but then the above example doesn't even 
compile.  I assumed you were talking about something like this:

Foo f;
Bar b;
try {
     f = dofoo();
     b = dobar();
} catch( Object o ) {
     delete f; delete b;
}

It's quite possible for f and b to both be uninitialized, yet I would 
expect the delete calls to be well-defined anyway.

Sean



More information about the Digitalmars-d mailing list