This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug in unexpected exceptions?



This program works with xlC but crashes with egcs-2.90.11.
Is this a bug or is the unexpected exception facility not fully supported?
I am using linux-2.0.28 and libc-5.4.39.

Peter                                        

peter:/dos/peter$ cat demo.C
#include <stdlib.h>
#include <iostream.h>
#ifdef  __xlC__
#include <unexpected.h>
#endif
class A  { };
class B  { };

void
f(int i)
throw(A)
{
  if (i == 1)
    { cout << "throwing A; ";  throw A();  }
  if (i == 2)
    {
        cout << "throwing B; ";
        throw B();
    }
  cout << "returning normally; ";
}

void
myunexpected()
{
  cout << "unexpected exception!" << endl;
  throw;     
}

int main()
{
  set_unexpected(myunexpected);

  for (int i = 0; i < 3; ++i) {
    try {
      cout << "trying: ";
      f(i);
      cout << "no exception thrown\n";
    }
    catch (A) {
        cout << "caught  A" << endl;
    }
    catch (B) {
        cout << "caught  B" << endl;
    }
//     catch (...) {
//         cout << "this should never happen"<< endl;
//    }
  }
  return 0;
}

peter:/dos/peter$ g++ -v -o demo demo.C -g -W -Wall
Reading specs from /usr/lib/gcc-lib/i386-pc-linux-gnulibc1/egcs-2.90.11/specs
gcc version egcs-2.90.11 970929 (gcc2-970802 experimental)
 /usr/lib/gcc-lib/i386-pc-linux-gnulibc1/egcs-2.90.11/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=90 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -g -W -Wa
ll -Di386 -Asystem(unix) -Acpu(i386) -Amachine(i386) -D__i386__ -Asystem(unix) -Acpu(i386) -Amachine(i386) demo.C /dos/tmp/cca05346.ii
GNU CPP version egcs-2.90.11 970929 (gcc2-970802 experimental) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++
 /usr/local/include
 /usr/i386-pc-linux-gnulibc1/include
 /usr/lib/gcc-lib/i386-pc-linux-gnulibc1/egcs-2.90.11/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-pc-linux-gnulibc1/egcs-2.90.11/cc1plus /dos/tmp/cca05346.ii -quiet -dumpbase demo.cc -g -W -Wall -version -o /dos/tmp/cca05346.s
GNU C++ version egcs-2.90.11 970929 (gcc2-970802 experimental) (i386-pc-linux-gnulibc1) compiled by GNU C version egcs-2.90.11 970929 (gcc2-970802 experimental).
 as -V -Qy -o /dos/tmp/cca053461.o /dos/tmp/cca05346.s
GNU assembler version 970712 (i586-linux), using BFD version linux-2.8.1.0.13
 /usr/lib/gcc-lib/i386-pc-linux-gnulibc1/egcs-2.90.11/ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.1 -o demo /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i386-pc-linux-gnulibc1/egcs-2.90.11/crtbegin.o -L/usr/lib/gcc-lib/i386-pc-linux-gnulibc1/egcs-
2.90.11 /dos/tmp/cca053461.o -lstdc++ -lm -lgcc -lc -lgcc /usr/lib/gcc-lib/i386-pc-linux-gnulibc1/egcs-2.90.11/crtend.o /usr/lib/crtn.o
peter:/dos/peter$ ./demo
trying: returning normally; no exception thrown
trying: throwing A; caught  A
trying: throwing B; unexpected exception!
IOT trap/Abort
peter:/dos/peter$ gdb demo
Current directory is /dos/peter/
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.16 (i386-unknown-linux), Copyright 1996 Free Software Foundation, Inc...
Breakpoint 1 at 0x80490b6: file demo.C, line 17.
(gdb) r
Starting program: /dos/peter/demo 
trying: returning normally; no exception thrown
trying: throwing A; caught  A

Breakpoint 1, f (i=2) at demo.C:17
(gdb) n
(gdb) s
__tf1B () at demo.C:52
(gdb) s
trying: throwing B; unexpected exception!

Program received signal SIGABRT, Aborted.
0x4006c665 in __kill ()
(gdb) where
#0  0x4006c665 in __kill ()
#1  0x40074301 in raise (sig=134530448)
#2  0x40035d26 in terminate ()
#3  0x804914f in f (i=2) at demo.C:20
#4  0x804924d in main () at demo.C:37
#5  0x8048fae in ___crt_dummy__ ()



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]