public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/52320] New: missing destructor call after thrown exception in initializer
@ 2012-02-21  1:03 mmehlich at semanticdesigns dot com
  2012-02-21  8:38 ` [Bug c++/52320] " daniel.kruegler at googlemail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: mmehlich at semanticdesigns dot com @ 2012-02-21  1:03 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52320
           Summary: missing destructor call after thrown exception in
                    initializer
    Classification: Unclassified
           Product: gcc
           Version: 4.5.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: mmehlich@semanticdesigns.com


The following example has constructors of class A called 4 times but
destructors only 3 times. 

Apparently, if an exception is thrown during the construction of an aggregate
class, the destructors of already constructed data members are not called.

#include <iostream>

#define FUNCTION_NAME __PRETTY_FUNCTION__

#define TRACE_FUNCTION { std::cout << this << "->" << FUNCTION_NAME <<
std::endl; }

struct A {
    A() { TRACE_FUNCTION; }
    A(int) { TRACE_FUNCTION; }
    A(const A&) { TRACE_FUNCTION; }
    A &operator=(const A&) TRACE_FUNCTION;
    ~A() TRACE_FUNCTION;
};

int main() {
    try {
        struct X {
            A e1[2], e2;
        } 
        x2[3] = { 1, 2, 3, 4, (0, throw 9, 5), 6 };
    } catch (...) {
    }
}

Detailed version information:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-cygwin/4.5.3/lto-wrapper.exe
Target: i686-pc-cygwin
Configured with:
/gnu/gcc/releases/respins/4.5.3-3/gcc4-4.5.3-3/src/gcc-4.5.3/configure
--srcdir=/gnu/gcc/releases/respins/4.5.3-3/gcc4-4.5.3-3/src/gcc-4.5.3
--prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin
--libexecdir=/usr/lib --datadir=/usr/share --localstatedir=/var
--sysconfdir=/etc --datarootdir=/usr/share --docdir=/usr/share/doc/gcc4 -C
--datadir=/usr/share --infodir=/usr/share/info --mandir=/usr/share/man -v
--with-gmp=/usr --with-mpfr=/usr --enable-bootstrap
--enable-version-specific-runtime-libs --libexecdir=/usr/lib --enable-static
--enable-shared --enable-shared-libgcc --disable-__cxa_atexit --with-gnu-ld
--with-gnu-as --with-dwarf2 --disable-sjlj-exceptions
--enable-languages=ada,c,c++,fortran,java,lto,objc,obj-c++ --enable-graphite
--enable-lto --enable-java-awt=gtk --disable-symvers --enable-libjava
--program-suffix=-4 --enable-libgomp --enable-libssp --enable-libada
--enable-threads=posix --with-arch=i686 --with-tune=generic
--enable-libgcj-sublibs CC=gcc-4 CXX=g++-4 CC_FOR_TARGET=gcc-4
CXX_FOR_TARGET=g++-4 GNATMAKE_FOR_TARGET=gnatmake GNATBIND_FOR_TARGET=gnatbind
--with-ecj-jar=/usr/share/java/ecj.jar
Thread model: posix
gcc version 4.5.3 (GCC)


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-01-07  0:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-21  1:03 [Bug c++/52320] New: missing destructor call after thrown exception in initializer mmehlich at semanticdesigns dot com
2012-02-21  8:38 ` [Bug c++/52320] " daniel.kruegler at googlemail dot com
2012-02-21 10:49 ` redi at gcc dot gnu.org
2012-02-21 10:56 ` daniel.kruegler at googlemail dot com
2020-03-11  7:00 ` jakub at gcc dot gnu.org
2020-05-07 11:56 ` jakub at gcc dot gnu.org
2020-07-23  6:51 ` rguenth at gcc dot gnu.org
2021-04-08 12:02 ` rguenth at gcc dot gnu.org
2022-01-07  0:24 ` cvs-commit at gcc dot gnu.org
2022-01-07  0:30 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).