Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exceptions - Is this a know problem?

21 views
Skip to first unread message

Per Martin

unread,
Jan 6, 1998, 3:00:00 AM1/6/98
to

Following code seems to work differently between 16 and 32 bit.

I am using 5.02 with patch 1.

Per Martin Pettersson
Q-Matic Sweden AB


// Code....

#include <iostream.h>
#include <conio.h>

//--------------------------------------------------------

class Error
{
public:
Error() { cout << "CTOR Error adr: " << (Adr=(long)this) << endl; }
explicit Error( const Error& ref ) { cout << "CTOR copy Error: " << ref.Adr << " -> "<< ((long)this) << endl; *this=ref; Adr=(long)this; }
~Error() { cout << "DTOR Error adr: " << Adr << " this: " << (long)this << endl; }
long Adr;
};

class Base1
{
public:
Base1() { cout << "CTOR Base1 adr: " << (Adr=(long)this) << endl; }
explicit Base1( const Base1& ref ) { cout << "CTOR copy Base1: " << ref.Adr << " -> "<< ((long)this) << endl; *this=ref; Adr=(long)this; }
~Base1() { cout << "DTOR Base1 adr: " << Adr << " this: " << (long)this << endl; }
Base1 &operator = ( const Base1 & );
long Adr;
};

class Base2
{
public:
Base2() { cout << "CTOR Base2 adr: " << (Adr=(long)this) << endl; }
explicit Base2( const Base2& ref ) { cout << "CTOR copy Base2: " << ref.Adr << " -> "<< ((long)this) << endl; *this=ref; Adr=(long)this; }
~Base2() { cout << "DTOR Base2 adr: " << Adr << " this: " << (long)this << endl; }
Base2 &operator = ( const Base2 & );
long Adr;
};

class Class1 : virtual public Base1, virtual public Base2
{
public:
Class1();
explicit Class1( const Class1& ref ) { cout << "CTOR copy Class1: " << ref.Adr << " -> "<< ((long)this) << endl; *this=ref; Adr=(long)this; }
virtual ~Class1();
Class1 &operator = ( const Class1 & );
long Adr;
};

class Class2 : public Class1
{
public:
Class2();
explicit Class2( const Class2& ref ) { cout << "CTOR copy Class2: " << ref.Adr << " -> "<< ((long)this) << endl; *this=ref; Adr=(long)this; }
virtual ~Class2();
Class2 &operator = ( const Class2 & );
long Adr;
};

class Class3 : public Class2
{
public:
Class3();
explicit Class3( const Class3& ref ) { cout << "CTOR copy Class3: " << ref.Adr << " -> "<< ((long)this) << endl; *this=ref; Adr=(long)this; }
virtual ~Class3();
Class3 &operator = ( const Class3 & );
long Adr;
};


//--------------------------------------------------------

Class1::Class1()
{
cout << "CTOR Class1 adr: " << (Adr=(long)this) << endl;

// throw Error(); // Virtual Base1 DTOR twice, not in 16bit
}
Class1::~Class1() { cout << "DTOR Class1 adr: " << Adr << " this: " << (long)this << endl; }

Class2::Class2()
{
cout << "CTOR Class2 adr: " << (Adr=(long)this) << endl;

throw Error(); // Virtual Base1 and Base 2 DTOR twice, not in 16bit
}
Class2::~Class2() { cout << "DTOR Class2 adr: " << Adr << " this: " << (long)this << endl; }

Class3::Class3()
{
cout << "CTOR Class3 adr: " << (Adr=(long)this) << endl;

// throw Error(); // Ok
}
Class3::~Class3() { cout << "DTOR Class3 adr: " << Adr << " this: " << (long)this << endl; }

//--------------------------------------------------------

void main ( void )
{
#ifdef __FLAT__
cout << "Start testing 32-bits" << endl;
#else
cout << "Start testing 16-bits" << endl;
#endif
try
{
Class3 test;
}
catch(Error err )
{
cout << "Catched error at ref: " << (long)&err << endl;
}
cout << "End of testing" << endl;

getch();
}

//--------------------------------------------------------

/*

Start testing 32-bits
CTOR Base1 adr: 1245056 // a
CTOR Base2 adr: 1245060 // b
CTOR Class1 adr: 1245032 // c
CTOR Class2 adr: 1245032 // d
CTOR Error adr: 1244908 // e
CTOR copy Error: 1244908 -> 8990626 // f
DTOR Base2 adr: 1245060 this: 1245060 // -b incorrect order
DTOR Base1 adr: 1245056 this: 1245056 // -a incorrect order
DTOR Base2 adr: 1245060 this: 1245060 // once more?
DTOR Base1 adr: 1245056 this: 1245056 // once more?
CTOR copy Error: 8990626 -> 1245064 // g
Catched error at ref: 1245064
DTOR Error adr: 8990626 this: 8990626 // -f
DTOR Error adr: 1245064 this: 1245064 // -g
End of testing


Start testing 16-bits
CTOR Base1 adr: 364838888 // a ok
CTOR Base2 adr: 364838892 // b ok
CTOR Class1 adr: 364838870 // c ok
CTOR Class2 adr: 364838870 // d never completed ok!
CTOR Error adr: 364838796 // e ok
CTOR copy Error: 364838796 -> 364780030 // f ok
DTOR Error adr: 364838796 this: 364838796 // -e
DTOR Class1 adr: 364838870 this: 364838870 // -c
DTOR Base2 adr: 364838892 this: 364838892 // -b
DTOR Base1 adr: 364838888 this: 364838888 // -a
CTOR copy Error: 364780030 -> 364838896 // g ok
Catched error at ref: 364838896
DTOR Error adr: 364780030 this: 364780030 // -f
DTOR Error adr: 364838896 this: 364838896 // -g
End of testing
*/


Mark Mathews

unread,
Jan 13, 1998, 3:00:00 AM1/13/98
to

Exception handling in 5.02 is known to call destructors on objects that were
never constructed. The problem only seems to show up in 32 bit targets. This
bug is known by Borland, but they don't seem to care. Others have reported
this bug as well as myself. When I reported the bug to Borland a several
months ago, this is the response I eventually got:

Dear Mark Mathews,

This reply regards BugRef 13769.

Thank you for submitting your bug report. I have been able to reproduce the
problem you have reported. All information has been forwarded to Research
and Development for further investigation and correction.

Thank you.
Anduin Withers, Developer Support


Well, it's been at least 4 months, and the bug has never been addressed.
Borland is soundly asleep at the wheel and is about to lose yet more
customers.

The only work around is to go back to 5.01 or don't use C++ exception
handling, which is a slap in the face to those of use who chose Borland
specifically for their support of the full C++ standard.

-Mark

Martin

unread,
Jan 29, 1998, 3:00:00 AM1/29/98
to

Yes it is a pity they can't fix it faster.

If they are working on something new it better be
really good, otherwise they are not excused for
the lack of bug fixing.

Thanks

Per Martin


0 new messages