[Bug c++/53868] New: Temporary for indirect binding is not destroyed when destructor from initializer temp throws

hstong at ca dot ibm.com gcc-bugzilla@gcc.gnu.org
Fri Jul 6 03:21:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53868

             Bug #: 53868
           Summary: Temporary for indirect binding is not destroyed when
                    destructor from initializer temp throws
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: hstong@ca.ibm.com
              Host: powerpc64-unknown-linux-gnu
            Target: powerpc64-unknown-linux-gnu


The temporary created for indirect binding should be completely constructed
(and from the output _it is_) before the destructors for temporaries in the
initializer are called.

In the following case, the destructor for a temporary in the initializer throws
an int. During stack unwinding, it seems the temporary bound to the reference
is missed.

### Self-contained source:> cat tempbindIndirect_inittempDtorThrows.cpp
extern "C" int printf(const char *, ...);
extern "C" void abort();

struct SubobjectInA {
   SubobjectInA();
   ~SubobjectInA();
};

struct A : SubobjectInA {
   A() = delete;
   A(const A &) = delete;
   A(A &&) { }
   A(int);
   ~A();
};

#define TRACE_FUNC( ... ) \
{   printf("%s\n", __PRETTY_FUNCTION__); __VA_ARGS__   }

struct Q {
   Q() : q(0)  TRACE_FUNC()
   ~Q();
   int q;
};

int main() {
   try { const A &a = Q().q; }
   catch (...) { return 0; }
   abort();
}

SubobjectInA::SubobjectInA()  TRACE_FUNC()
SubobjectInA::~SubobjectInA()  TRACE_FUNC()
A::A(int)  TRACE_FUNC()
A::~A()  TRACE_FUNC()
Q::~Q()  TRACE_FUNC( throw 0; )


### Compiler invocation:
g++-4.7.0 -std='c++11' tempbindIndirect_inittempDtorThrows.cpp -o test


### Compiler output:
(return code 0)


### Output from resulting executable:> ./test ; echo rc=$?
Q::Q()
SubobjectInA::SubobjectInA()
A::A(int)
Q::~Q()
rc=0


### Expected output:
Q::Q()
SubobjectInA::SubobjectInA()
A::A(int)
Q::~Q()
A::~A()
SubobjectInA::~SubobjectInA()
rc=0


### gcc -v output:> g++-4.7.0 -v
Using built-in specs.
COLLECT_GCC=g++-4.7.0
COLLECT_LTO_WRAPPER=/data/gcc/libexec/gcc/powerpc64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: powerpc64-unknown-linux-gnu
Configured with: ../gcc-4.7.0/configure --prefix=/data/gcc
--program-suffix=-4.7.0 --disable-libssp --disable-libgcj
--enable-version-specific-runtime-libs --with-cpu=default32 --enable-secureplt
--with-long-double-128 --enable-shared --enable-__cxa_atexit
--enable-threads=posix --enable-languages=c,c++,fortran --with-mpfr=/usr/local/
--with-mpc=/usr/local/ --with-gmp=/usr/local/
Thread model: posix
gcc version 4.7.0 (GCC)



More information about the Gcc-bugs mailing list