c++/3775: dtor of auto variable outside a try loop is not called in exception unwinding

sll@uk.research.att.com sll@uk.research.att.com
Mon Jul 23 08:16:00 GMT 2001


>Number:         3775
>Category:       c++
>Synopsis:       dtor of auto variable outside a try loop is not called in exception unwinding
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 23 08:16:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Sai Lai Lo
>Release:        3.0
>Organization:
AT&T Laboratories- Cambridge
>Environment:
System: Linux neem.uk.research.att.com 2.4.6patched #2 SMP Tue Jul 10 14:32:14 BST 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../configure --prefix=/usr/local/gcc --enable-threads=posix --enable-languages=c++
>Description:
The dtor of an auto variable outside a try loop is not called when an 
uncaught exception inside the try loop unwinds.
>How-To-Repeat:
This simple test code can reproduce the problem.
The output should be:

A()
~A()
Got long 0

Instead the output is

A()
Got long 0


------
#include <iostream.h>

class A {
public:
  A() {
    cerr << "A()" << endl;
  }

  ~A() {
    cerr << "~A()" << endl;
  }
 
};
 
void f() {
  A a;
 
  try {
    throw long(0);
  }
  catch(int&) {
    cerr << "Got int exception" << endl;
  }
}
 
 
int
main(int,char**) {
  try {
    f();
  }
  catch(long& v) {
    cerr << "Got long " << v << endl;
  }
  return 0;
}
-------
 
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list