I configure the fstream like this:

    ifstream is; 
    is.exceptions(ifstream::badbit | ifstream::failbit);
    is.open(filename, ifstream::in | ifstream::binary);

When it tries to open a file that does not exist, it throws an exception just
as it should. If this is immediately inside a try/catch block it works. If it
is inside a function call however, the program segfaults.

I believe that the problem is inside the ifstream class. Further testing showed
that declaring a function like this:
void f() {
  ifstream is;
  throw 1;
}
also causes a segfault.

If the exception is not caught in the functions above f() there is an exception
abort but no segfault.

I tried this on GCC 4.4.1 and 4.4.2, both from SVN. GCC 4.3 from Fedora does
not do this.

I believe that the problem is in the libraries, not the GCC binary, because the
Fedora GCC *does* show the problem if I allow it to link to the libraries from
GCC 4.4.2. A -static build on GCC 4.3 works, and a -static build on GCC 4.4.2
fails.

Binutils are Fedora 9 default:
$ ld -v
GNU ld version 2.18.50.0.6-2 20080403


I configured my SVN GCCs like this:
$ gcc -v
Using built-in specs.
Target: ia64-redhat-linux
Configured with: ../configure --prefix=/opt/gcc-4.4 --enable-shared
--enable-threads=posix --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-languages=c,c++
--build=ia64-redhat-linux
Thread model: posix
gcc version 4.4.2 20090722 (prerelease) (GCC) 

Fedora 9's GCC is configured like this:
$ /usr/bin/gcc -v
Using built-in specs.
Target: ia64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--build=ia64-redhat-linux
Thread model: posix
gcc version 4.3.0 20080428 (Red Hat 4.3.0-8) (GCC)


-- 
           Summary: Application segfaults when throwing an exception that
                    destroys an fstream
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: zlynx at acm dot org
  GCC host triplet: ia64-redhat-linux


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

Reply via email to