[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::c_plus_plus

Title:C++
Notice:Read 1.* and use keywords (e.g. SHOW KEY/FULL KIT_CXX_VAX_VMS)
Moderator:DECCXX::AMARTIN
Created:Fri Nov 06 1987
Last Modified:Thu Jun 05 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:3604
Total number of notes:18242

3444.0. "throw inside destructor of automatic object results in multiple destructor calls" by KZIN::HUDSON (That's what I think) Tue Feb 11 1997 14:18

I can't see anything in then notesfile on this specific issue, and so far as
I can see the customer appears to have a point.  Or is there something in the
ARM that forbids what he's trying to do?

(I reproduced this with C++ 5.5-004)

Thanks for any comments

nick

////////////////////////////////////////////////////////////////////////////////

I'm compiling some C++ code on Digital UNIX 4.0 and am getting a problem with 
exceptions in distructors. The problem is that when the destructor is called 
and throws an exception, all the local objects are destructed twice, causing 
the heap to become corrupted.


If you run this test program.....

---------------------------------------------------------

 #include <iostream.h>

class EnvExcRaiser {
public:
    EnvExcRaiser ()  { cout << "Default CTR EnvExcRaiser " << endl; }
    ~EnvExcRaiser () { cout << "Default DTR EnvExcRaiser " << endl; throw 0; }
};

class account {
public:
    account ()  { cout << "Default CTR account " << (void*)this << endl; }
    ~account () { cout << "Default DTR account " << (void*)this << endl; }
};


int fun()
{
    EnvExcRaiser ex;
    account accountPtr;
    return 0;
}


int main()
{
    try {
        fun();
    }
    catch (...) {
        cout << "Exception raised" << endl;
    }
    return 0;
}

---------------------------------------------------------

...... it gives the following output.


Default CTR EnvExcRaiser 
Default CTR account 0x11ffff7d0
Default DTR account 0x11ffff7d0
Default DTR EnvExcRaiser 
Default DTR account 0x11ffff7d0
Default DTR EnvExcRaiser 
IOT/Abort trap (core dumped)


Is there a fix available for this?


uname -a
OSF1 behemoth V4.0 464 alpha

T.RTitleUserPersonal
Name
DateLines
3444.1not being ignoredHNDYMN::MCCARTHYA Quinn Martin ProductionThu Feb 13 1997 14:253
We are looking into this.

bjm
3444.2Need assignment to __current_try_block_decl before each dtorWIDTH::MDAVISMark Davis - compiler maniacFri Feb 14 1997 16:3717
Looks like we're not  updating __current_try_block_decl immediately
BEFORE each destructor is called

int fun()
{
 __current_try_block_decl =0;
    EnvExcRaiser ex;
 __current_try_block_decl =1;
    account accountPtr;
 __current_try_block_decl =2;

	// missing  __current_try_block_decl =1;
implicit accountPtr.~account();
	// missing  __current_try_block_decl =0;
implicit ex.~EnvExcRaiser();

    return 0;
3444.3DECCXX::COLEENTue May 27 1997 18:1823
This was a bug in the compiler and has been fixed for the V6.0
release of DEC C++.  As properly diagnosed in .-1, the cleanup
context wasn't updated correctly for a return statement.  Since the
destructor was called for a return statement that raised the exception,
the wrong context was used.  This is gross, but the workaround is this:

int fun()
{
  {
    EnvExcRaiser ex;
    account accountPtr;
  }
    return 0;
}

DEC C++ V5.n was not designed to handle cleanup properly from exceptions
thrown in destructors.  The design of V6.0 fixes this class of problems.

Thanks for reporting this problem.

Coleen Phillimore
DEC C++ development