Exception allocation bug?

Mike Harrold mharrold@cas.org
Sat Jul 5 17:42:00 GMT 2003


Hi,

I don't know if this is a bug or a feature, but I am wondering why
the following code:

  throw MyException();

results in the following:

  MyException is constructed on the stack using default ctor.
  __cxa_allocate_exception is called
  A second MyException is constructed using the memory returned by
     __cxa_allocate_exception, using MyException's copy ctor.
  The first MyException is destroyed.

Couldn't this be optimised to:

  __cxa_allocate_exception is called
  MyException is constructed using the memory returned by
     __cxa_allocate_exception, using MyExceptions' default ctor.

Thanks,

/Mike



More information about the Gcc-bugs mailing list