Bug 20976 - when terminate is called, stack is not unwinded
Summary: when terminate is called, stack is not unwinded
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.4
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: documentation
: 40066 (view as bug list)
Depends on:
Reported: 2005-04-12 18:45 UTC by Christos Kloukinas
Modified: 2009-05-08 16:21 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2005-07-12 00:06:16

The .ii intermediate file (bzip2 compressed) of the testcase I used. (75.45 KB, application/x-bzip)
2005-04-12 18:48 UTC, Christos Kloukinas
And the testcase itself... (347 bytes, text/x-c++src)
2005-04-12 18:52 UTC, Christos Kloukinas

Note You need to log in before you can comment on or make changes to this bug.
Description Christos Kloukinas 2005-04-12 18:45:33 UTC
Sorry, cannot understand how to attach the different files you ask for or what
the host/target/build triplets are supposed to be (no mention of these in the

The bug: I was under the impression, that if an exception occurs the destructors
of the local objects should be called at some point, even if we don't catch the
exception anywhere.
The behaviour however of g++ (tried it with 3.4.4 and 3.3.5) is different.
It only executes the destructors if the exception is caught somewhere (doesn't
matter if it's rethrown or not).

Platform / Compiler info & test program follow.

Take care & thanks for the great work! :-)

$ uname -a
Linux adia #1 SMP Tue Oct 5 03:46:19 CEST 2004 i686 GNU/Linux
$ g++-3.4 -v -save-temps exceptions.cc -o exceptions
Reading specs from /usr/lib/gcc/i486-linux/3.4.4/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.4
--enable-shared --with-system-zlib --enable-nls --without-included-gettext
--program-suffix=-3.4 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt
--enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm
--enable-java-awt=gtk --disable-werror i486-linux
Thread model: posix
gcc version 3.4.4 20041218 (prerelease) (Debian 3.4.3-6)
 /usr/lib/gcc/i486-linux/3.4.4/cc1plus -E -quiet -v -D_GNU_SOURCE exceptions.cc
-mtune=i486 -o exceptions.ii
ignoring nonexistent directory
#include "..." search starts here:
#include <...> search starts here:
End of search list.
 /usr/lib/gcc/i486-linux/3.4.4/cc1plus -fpreprocessed exceptions.ii -quiet
-dumpbase exceptions.cc -mtune=i486 -auxbase exceptions -version -o exceptions.s
GNU C++ version 3.4.4 20041218 (prerelease) (Debian 3.4.3-6) (i486-linux)
        compiled by GNU C version 3.4.4 20041218 (prerelease) (Debian 3.4.3-6).
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=64194
 as -V -Qy --32 -o exceptions.o exceptions.s
GNU assembler version 2.15 (i386-linux) using BFD version 2.15
 /usr/lib/gcc/i486-linux/3.4.4/collect2 --eh-frame-hdr -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o exceptions
/usr/lib/gcc/i486-linux/3.4.4/crtbegin.o -L/usr/lib/gcc/i486-linux/3.4.4
-L/usr/lib/gcc/i486-linux/3.4.4 -L/usr/lib/gcc/i486-linux/3.4.4/../../../../lib
-L/usr/lib/gcc/i486-linux/3.4.4/../../.. -L/lib/../lib -L/usr/lib/../lib
exceptions.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
$ ./exceptions
  Unknown exception
terminate called after throwing an instance of 'B'

Here's the program (email me for the .ii.bz file - couldn't spot any "attach"

#include <iostream>
using namespace std;
class A {
   static int last_id;
   int id;
   virtual ~A();
int A::last_id = 0;

A::A() : id(++last_id) {}
A::~A() { cerr << '\t' << id << '\n'; }

// class B : public A {}; // B is a subclass of A
class B {}; // B now has no relationship to A

void f() {
   A a1;
   A a2;

   try {
     throw B();
   } catch (A a) {
     cerr << "  Caught an A : " << a.id << '\n';
   } catch (...) {
     cerr << "  Unknown exception\n";
     throw; // rethrow it

int main() {
#ifdef OK
   try {
   } catch (...) {
   // BUG: Shouldn't it have executed the destructors of a1,a2 (f's local vars)
before exiting???
   return 0;
Comment 1 Christos Kloukinas 2005-04-12 18:48:10 UTC
Created attachment 8612 [details]
The .ii intermediate file (bzip2 compressed) of the testcase I used.
Comment 2 Christos Kloukinas 2005-04-12 18:52:45 UTC
Created attachment 8613 [details]
And the testcase itself...
Comment 3 Andrew Pinski 2005-04-12 19:01:57 UTC
I don't think this is valid as there is no landing pad and it is going to abort anyways.  I have to find this 
in the standard.  ICC has the same behavior.
Comment 4 Andrew Pinski 2005-04-12 19:23:15 UTC
Ok, this is just implemenation defined behavior.
see 15.3 P 9:
If no matching handler is found in a program, the function terminate() is called; whether or not the 
stack is unwound before this call to terminate() is implemenation-defined (15.5.1)

So we define it as not unwinding but we don't document this.

Confirmed for documentation.
Comment 5 Andrew Pinski 2009-05-08 16:21:58 UTC
*** Bug 40066 has been marked as a duplicate of this bug. ***