[Bug c++/87637] New: Unwinding does not destroy constructed subobject of brace-initialized temporary

hstong at ca dot ibm.com gcc-bugzilla@gcc.gnu.org
Wed Oct 17 20:22:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87637

            Bug ID: 87637
           Summary: Unwinding does not destroy constructed subobject of
                    brace-initialized temporary
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hstong at ca dot ibm.com
  Target Milestone: ---

In the following program, the initialization of the A subobject of the B
temporary associated with the brace-initializing cast expression is complete
when an exception is thrown during the further initialization of the B
temporary.

When compiled with GCC, stack unwinding for the exception fails to invoke the
destructor of the A subobject.

### SOURCE (<stdin>):
extern "C" int printf(const char *, ...);

struct A {
  A() { printf("%s\n", __PRETTY_FUNCTION__); }
  A(const A &) = delete;
  ~A() { printf("%s\n", __PRETTY_FUNCTION__); }
};

struct B { A a; int q; };

int foo() { throw 0; }

int main(void) {
  try {
    (void) B{{}, foo()};
  }
  catch (...) { }
}


### COMPILER INVOCATION:
g++ -x c++ -std=c++11 -o prog -


### RUN INVOCATION:
./prog


### ACTUAL RUN OUTPUT:
A::A()


### EXPECTED RUN OUTPUT:
A::A()
A::~A()


### COMPILER VERSION INFO (g++ -v):
Using built-in specs.
COLLECT_GCC=/opt/wandbox/gcc-head/bin/g++
COLLECT_LTO_WRAPPER=/opt/wandbox/gcc-head/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../source/configure --prefix=/opt/wandbox/gcc-head
--enable-languages=c,c++ --disable-multilib --without-ppl --without-cloog-ppl
--enable-checking=release --disable-nls --enable-lto
LDFLAGS=-Wl,-rpath,/opt/wandbox/gcc-head/lib,-rpath,/opt/wandbox/gcc-head/lib64,-rpath,/opt/wandbox/gcc-head/lib32
Thread model: posix
gcc version 9.0.0 20181016 (experimental) (GCC)


More information about the Gcc-bugs mailing list