Error throwing reference result of a function call

Andrey Slepuhin pooh@msu.net
Mon Jan 26 16:56:00 GMT 1998


The following example fails under egcs-980115 and egcs-980122,
but works fine under egcs-971225 on powerpc-ibm-aix4.2.1.0:
----------test.cc-----------
#include <iostream.h>

struct X
{
  X ()
  {
    cerr<<"X():"<<this<<endl;
  }
  X (X const& x)
  {
    cerr<<"X(X&):"<<this<<endl;
  }
  ~X ()
  {
    cerr<<"~X():"<<this<<endl;
  }
};

inline X const& f(X const& x)
{
  return x;
} 

void main ()
{
  try {
    throw f(X());
  } catch (...) {
    cerr<<"catched"<<endl;
  }
}
===============================
output if compiled with egcs-980115 or egcs-980122:
-------------------------------
X():0x2ff22970
X(X&):0x2000b868
~X():0x2ff22968
^^^^^^^^^^^^^^^ - What object is destroyed ???
~X():0x2ff22970
catched
~X():0x2000b868
===============================
output if compiled with egcs-971225:
-------------------------------
X():0x2ff22998
X(X&):0x20091e78
~X():0x2ff22998
catched
~X():0x20091e78
===============================

Andrey.




More information about the Gcc mailing list