[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#511200: g++-4.3: doesn't work destructor of local object



Package: g++-4.3
Version: 4.3.2-1.1
Severity: normal

In the example below destructor of local object doesn't work (there is no
output from it). However, if the call of f() is wrapped into

  try {
    f();
  }
  catch (...) {
    throw;
  }

then the destructor produces expected output. Here is the result of running
the program without catch(...):

$ g++ -o test -DNO_TRY -Wall -Wextra -pedantic test.cc
$ ./test
constructing MyTest@0xff7fd0ff
terminate called after throwing an instance of 'MyError'
Aborted

And now with handler:

$ g++ -o test -Wall -Wextra -pedantic test.cc
$ ./test
constructing MyTest@0xff93ca1f
destructing MyTest@0xff93ca1f
terminate called after throwing an instance of 'MyError'
Aborted

The program (test.cc):

#include <iostream>
using namespace std;

class MyTest {
public:
  MyTest() { cout << "constructing MyTest@" << this << '\n'; cout.flush(); }
  ~MyTest() { cout << "destructing MyTest@" << this << '\n'; cout.flush(); }
};

class MyError {};

void f()
{
  MyTest m;
  throw MyError();
}

int main()
{
#ifdef NO_TRY
  f();
#else
  try {
    f();
  }
  catch (...) {
    throw;
  }
#endif
}

-- System Information:
Debian Release: 5.0
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: i386 (x86_64)

Kernel: Linux 2.6.26-1-amd64 (SMP w/2 CPU cores)
Locale: LANG=ru_RU.UTF-8, LC_CTYPE=ru_RU.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages g++-4.3 depends on:
ii  gcc-4.3                   4.3.2-1.1      The GNU C compiler
ii  gcc-4.3-base              4.3.2-1.1      The GNU Compiler Collection (base 
ii  libc6                     2.7-18         GNU C Library: Shared libraries
ii  libgmp3c2                 2:4.2.2+dfsg-3 Multiprecision arithmetic library
ii  libmpfr1ldbl              2.3.2.dfsg.1-1 multiple precision floating-point 
ii  libstdc++6-4.3-dev        4.3.2-1.1      The GNU Standard C++ Library v3 (d

g++-4.3 recommends no packages.

Versions of packages g++-4.3 suggests:
pn  g++-4.3-multilib             <none>      (no description available)
ii  gcc-4.3-doc                  4.3.2.nf1-1 documentation for the GNU compiler
pn  libstdc++6-4.3-dbg           <none>      (no description available)

-- no debconf information

-- 
Dmitri Paduchikh



Reply to: