gcc bug w/ uncaught_exception

Tudor Hulubei tudor@cs.unh.edu
Wed Nov 24 21:17:00 GMT 1999


Hi,

The appended code (bug.cc) compiles just fine but crashes in abort()
on RedHat 6.0/6.1, with egcs-1.1.2 & gcc-2.95.2.

If the `fstream' field is taken out from the `Stream' class, or if
~Stream is changed so that it only contains  "throw exception();", the 
code works ok (i.e. it aborts w/o a segmentation fault).

It also looks like the code works ok on SunOS 5.7 with gcc-2.8.1 or
egcs-1.1.  It also works ok on OSF1 V4.0 with gcc-2.95.1.

I've also noticed that compiling the thing statically, i.e.

c++ -static bug.cc

also fixes the bug.

Any idea why this is happening?  I'm not sure this is a bug in gcc -
it might be a glibc problem, but I'm posting it here just in case.

Thanks,
Tudor

[tudor@hal]:~ $ c++ bug.cc
[tudor@hal]:~ $ ./a.out
Segmentation fault (core dumped)

--

#include <fstream>
#include <stdexcept>


class Stream
{
  protected:
    fstream s;

  public:
    ~Stream()
    {
	if (uncaught_exception())
	    return;
	throw exception();
    }
};


int
f()
{
    Stream x;
    Stream y;
    return 0;
}


int
main()
{
    try { f(); }
    catch (...) { abort(); }
    return 0;
}



More information about the Gcc-bugs mailing list