c++/3757: 3.0 does not destroy local objects on throw
teemu@torma.org
teemu@torma.org
Sat Jul 21 02:16:00 GMT 2001
>Number: 3757
>Category: c++
>Synopsis: 3.0 does not destroy local objects on throw
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Sat Jul 21 02:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Teemu Torma
>Release: 3.0.1 20010720 (prerelease)
>Organization:
>Environment:
System: Linux dirham.labs.trema.com 2.4.6 #1 SMP Thu Jul 5 15:25:57 CEST 2001 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-3.0-branch/configure --with-gcc-version-trigger=/work/tot/gcc/3.0/gcc-3.0-branch/gcc/version.c --host=i686-pc-linux-gnu --prefix=/usr/local/gcc3 --enable-version-specific-runtime-libs --enable-long-long --enable-threads
>Description:
Local objects are not always destructed when an exception is
thrown and the object goes out of scope.
>How-To-Repeat:
Please see the following code. In ex_test, the local object
is not destructed if e1 is thrown, but is, if e2 would be
thrown. No compiler options are needed to reproduce the problem.
$ /usr/local/gcc3/bin/c++ -v ex.cc
Reading specs from /usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/specs
Configured with: ../gcc-3.0-branch/configure --with-gcc-version-trigger=/work/tot/gcc/3.0/gcc-3.0-branch/gcc/version.c --host=i686-pc-linux-gnu --prefix=/usr/local/gcc3 --enable-version-specific-runtime-libs --enable-long-long --enable-threads
Thread model: posix
gcc version 3.0.1 20010720 (prerelease)
/usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=1 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__NO_INLINE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ ex.cc -D__GNUG__=3 -D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase ex.cc -version -o /tmp/ccVtUJdM.sGNU CPP version 3.0.1 20010720 (prerelease) (cpplib) (i386 Linux/ELF)
GNU C++ version 3.0.1 20010720 (prerelease) (i686-pc-linux-gnu)
compiled by GNU C version 3.0.1 20010720 (prerelease).
#include "..." search starts here:
#include <...> search starts here:
/usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/include/g++
/usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/include/g++/i686-pc-linux-gnu
/usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/include/g++/backward
/usr/local/include
/usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/include
/usr/local/gcc3/i686-pc-linux-gnu/include
/usr/include
End of search list.
as --traditional-format -V -Qy -o /tmp/ccG2tDMQ.o /tmp/ccVtUJdM.s
GNU assembler version 2.10.91 (i386-redhat-linux) using BFD version 2.10.1.0.2
/usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/crtbegin.o -L/usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1 -L/usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/../../.. /tmp/ccG2tDMQ.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/crtend.o /usr/lib/crtn.o
$ ./a.out
a::a()
$
#include <iostream>
using namespace std;
struct a
{
a () { cerr << "a::a()\n"; }
~a () { cerr << "a::~a()\n"; }
};
struct e1 {};
struct e2 {};
void
ex_test ()
{
a aa;
try
{
// If this would be e2, aa would be destructed.
throw e1 ();
}
catch (e2 &)
{
}
}
int
main ()
{
try
{
ex_test ();
}
catch (...)
{
}
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list