The following program generates segmentation fault when exception is thrown from
constructor. The fault happens if type of CONTAINER is std::list or std::set,
but does not happen if its type is std::vector or if CONTAINER is ommited from
TST class. Also tested on linux with same resutls.
----  Program source:-----------------
#include <list>

class TST {
        std::list<int> CONTAINER;
public:
        TST(int i) {
                if (i==0) {
                        delete this;
                        throw 1;
                }
        }
        ~TST() {
                printf("Destructor\n");
        }
};

int main() {
        TST* tst = NULL;
        try {
                 tst = new TST(0);
        }
        catch (int i) {
                printf("Caught %d\n",i);
        }
        if (tst != NULL)
                delete tst;
}
-----------------------
Compile command output:
-----------------------
$ g++ -v -save-temps tst.cpp
Reading specs from C:/MinGW/bin/../lib/gcc-lib/mingw32/3.3.3/specs             
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as
--host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls
--enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry
--disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt
--without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter
--enable-hash-synchronization
Thread model: win32
gcc version 3.3.3 (mingw special)
 C:\MinGW\bin\..\lib\gcc-lib\mingw32\3.3.3\cc1plus.exe -E -D__GNUG__=3 -quiet -v
-iprefix C:\MinGW\bin\../lib/gcc-lib/mingw32/3.3.3/ -D__GNUC__=3
-D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=3 tst.cpp tst.ii
ignoring nonexistent directory "C:/MinGW/mingw32/include"
ignoring nonexistent directory "/mingw/mingw32/include"
#include "..." search starts here:
#include <...> search starts here:
 C:/MinGW/include/c++/3.3.3
 C:/MinGW/include/c++/3.3.3/mingw32
 C:/MinGW/include/c++/3.3.3/backward
 C:/MinGW/include
 C:/MinGW/lib/gcc-lib/mingw32/3.3.3/include
 /mingw/include/c++/3.3.3
 /mingw/include/c++/3.3.3/mingw32
 /mingw/include/c++/3.3.3/backward
 /mingw/include
 /mingw/include
 /mingw/lib/gcc-lib/mingw32/3.3.3/include
 /mingw/include
End of search list.
 C:\MinGW\bin\..\lib\gcc-lib\mingw32\3.3.3\cc1plus.exe -fpreprocessed tst.ii
-quiet -dumpbase tst.cpp -auxbase tst -version -o tst.s
GNU C++ version 3.3.3 (mingw special) (mingw32)
        compiled by GNU C version 3.3.3 (mingw special).
GGC heuristics: --param ggc-min-expand=60 --param ggc-min-heapsize=57214
 C:\MinGW\bin\..\lib\gcc-lib\mingw32\3.3.3\..\..\..\..\mingw32\bin\as.exe
--traditional-format -o tst.o tst.s
 C:\MinGW\bin\..\lib\gcc-lib\mingw32\3.3.3\..\..\..\..\mingw32\bin\ld.exe
-Bdynamic /mingw/lib/crt2.o C:/MinGW/bin/../lib/gcc-lib/mingw32/3.3.3/crtbegin.o
-LC:/MinGW/bin/../lib/gcc-lib/mingw32/3.3.3 -LC:/MinGW/bin/../lib/gcc-lib
-L/mingw/lib/gcc-lib/mingw32/3.3.3
-LC:/MinGW/bin/../lib/gcc-lib/mingw32/3.3.3/../../../../mingw32/lib
-L/mingw/lib/gcc-lib/mingw32/3.3.3/../../../../mingw32/lib -L/mingw/lib
-LC:/MinGW/bin/../lib/gcc-lib/mingw32/3.3.3/../../..
-L/mingw/lib/gcc-lib/mingw32/3.3.3/../../.. tst.o -lstdc++ -lmingw32 -lgcc
-lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32
-lgcc -lmoldname -lmingwex -lmsvcrt
C:/MinGW/bin/../lib/gcc-lib/mingw32/3.3.3/crtend.o

-- 
           Summary: Segmentation fault after exception in list and set
                    destructors
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vldmrrr at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: mingw32
  GCC host triplet: mingw32
GCC target triplet: mingw32


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

Reply via email to