This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8563: C++ Standard Issue ( 15.2.2 violation ) : Base class destructor is not called during exception handling.
- From: sunil dot k dot davasam at intel dot com
- To: gcc-gnats at gcc dot gnu dot org
- Cc: sunil dot k dot davasam at intel dot com
- Date: 13 Nov 2002 19:15:25 -0000
- Subject: c++/8563: C++ Standard Issue ( 15.2.2 violation ) : Base class destructor is not called during exception handling.
- Reply-to: sunil dot k dot davasam at intel dot com
>Number: 8563
>Category: c++
>Synopsis: C++ Standard Issue ( 15.2.2 violation ) : Base class destructor is not called during exception handling.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Nov 13 11:16:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: sunil.k.davasam@intel.com
>Release: gcc-3.2
>Organization:
>Environment:
I tried on IA32 Redhat8.0 product, with gcc3.2 compiler.
>Description:
This testcase has a exception in derived class destructor, there is no catch inside destructor. There is a matching catch in main(). This is to check whether the base class destructor is called during exception handling.
-------------------------t2.cpp........................
#include <stdio.h>
struct C1
{
virtual int f9() { return 1; }
C1() { printf("C1()\n" ); }
~C1() { printf("~C1()\n" ); }
};
struct C2 : public C1 {
C2() { printf("C2()\n" ); }
~C2() { printf("~C2()\n" ); throw 1; }
};
int main()
{
try {
C2 o2;
} catch ( C1 o1 ) {
printf("Catching C%d exception.\n",1 );
} catch ( int i ) {
printf("Catching int exception.\n" );
}
return 0;
}
----------------------------------------------
Expected output:
------------
C1()
C2()
~C2()
~C1()
Catching int exception.
-------------
Actual output:
--------
C1()
C2()
~C2()
Catching int exception.
--------
Based on C++ Standard ( except.ctor ) 15.2.2:
An object that is partially constructed or partially destroyed will have destructors executed for all of its fully constructed subobjects, that is, for subobjects for which the constructor has completed execution and the destructor has not yet begun execution.
-------
>How-To-Repeat:
[skdavasa@csattert1 failed_testcases]$ g++ t2.cpp
[skdavasa@csattert1 failed_testcases]$ a.out
C1()
C2()
~C2()
Catching int exception.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="t3.cpp"
Content-Disposition: inline; filename="t3.cpp"
#include <stdio.h>
struct C1
{
virtual int f9() { return 1; }
C1() { printf("C1()\n" ); }
~C1() { printf("~C1()\n" ); }
};
struct C2 : public C1 {
C2() { printf("C2()\n" ); }
~C2() { printf("~C2()\n" ); throw 1; }
};
int main()
{
try {
C2 o2;
} catch ( C1 o1 ) {
printf("Catching C%d exception.\n",1 );
} catch ( int i ) {
printf("Catching int exception.\n" );
}
return 0;
}