c++/8453: ABI Issue: Destructors for already constructed objects not called when the exception is thrown inside constructor.
sunil.k.davasam@intel.com
sunil.k.davasam@intel.com
Mon Nov 4 14:46:00 GMT 2002
>Number: 8453
>Category: c++
>Synopsis: ABI Issue: Destructors for already constructed objects not called when the exception is thrown inside constructor.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Nov 04 14:46:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: sunil.k.davasam@intel.com
>Release: gcc - 3.2
>Organization:
>Environment:
Redhat 8.0 product ( ia32 ),
United Linux 1.0 ( ia64 )
>Description:
Based on C++ ABI, ( Section 3.3.3: Array Construction and Destruction API )
While creating an array of objects, If the constructor throws an exception, call the destructor for any already-constructed elements, and rethrow the exception.
In the following example, The testcase wants to create an array of 4 objects. While creating 3rd object, it throws an exception. So, based on C++ ABI, destructors should be called for already constructed first 2 elements.
When I compiled the testcase with gcc 3.2 compiler, I am getting different output.
Contents of file : tt.cpp
-------------------------
#include <stdio.h>
static int i = 0;
struct C3
{
C3() {
if ( i == 2 )
throw 1;
else
i++;
printf("%sC%d()\n", "", 3);
}
~C3() {
printf("%sC%d()\n", "~", 3);
}
};
C3 o3[4];
int main()
{
return 0;
}
[cmd_prompt]$ g++ tt.cpp
[cmd_prompt]$ a.out
C3()
C3()
Abort (core dumped)
-----------
Expected output:
C3()
C3()
~C3()
~C3()
Abort (core dumped)
-----------
gcc compiler version:
[cmd]$ g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --host=i
386-redhat-linux --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2 (Red Hat Linux Rawhide 3.2-1)
Actually I tried on both IA32 and IA64 platforms.
IA32 - Redhat Linux 8.0 product
IA64 - United Linux 1.0
--------
>How-To-Repeat:
[cmd_prompt]$ g++ tt.cpp
[cmd_prompt]$ a.out
C3()
C3()
Abort (core dumped)
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-prs
mailing list