Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/C++/Front End/Destructors    [ Add a report in this area ]  
Report #:  90472   Status: Open
Failure when a constructor takes a copy of an object with an explicit destructoras an input and the same constructor throws an exception in the initializer list
Project:  C++Builder Build #:  15.0.3953.35171
Version:    15.0 Submitted By:   Øystein Svinning
Report Type:  Basic functionality failure Date Reported:  12/22/2010 6:03:12 AM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   281508
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
Classes:
ClassX
Has implemented a default constructor and a destructor

ClassY
Has implemented a default constructor

ClassA
Has a default constructor that throws an exception. It also has a destructor that should never be called as the exception in the constructor prevents ClassA from being properly constructed.

ClassB
Contains a pointer to ClassA. It has four different constructors that demonstrates three good and one bad way of trying to construct an instance of ClassA and assigning it to the pointer.


Cases:
1) Bad
Construct an object of ClassB by passing a copy of a ClassX object to the constructor. The constructor for ClassA tries to set the pointer to ClassB in the initializer list.
What should happen:
ClassB throws an exception in the destructor. The destructor of the local copy of ClassX is called.
What happens:
ClassB throws an exception in the destructor. The destructor of ClassB, which has not been properly constructed, is called. The destructor for the local copy of ClassX is not called.
Explanation:
The program confuses the destructors of ClassX and ClassA, and calls the wrong one?

2) Good
Construct an object of ClassB by passing a copy of a ClassY object to the constructor. The constructor for ClassA tries to set the pointer to ClassB in the initializer list.
What happens:
ClassB throws an exception in the destructor. The destructor for the local copy of ClassY is called.
Explanation:
This is as expected

3) Good
Construct an object of ClassB by passing a reference to a ClassX object to the constructor. The constructor for ClassA tries to set the pointer to ClassB in the initializer list.
What happens:
ClassB throws an exception in the destructor.
Explanation:
This is as expected

4) Good
Construct an object of ClassB by passing a copy of a ClassX object to the constructor. The constructor for ClassA tries to set the pointer to ClassB in the body of the destructor.
What happens:
ClassB throws an exception in the destructor. The destructor for the local copy of ClassX is called.
Explanation:
This is as expected


See the attached file BadDestructTest for the code example that shows this.
Steps to Reproduce:
None
Workarounds
None
Attachment
DestructorBug.zip
Comments

None

Server Response from: ETNACODE01