Lifetime of a temporary

Martin v. Loewis loewis@informatik.hu-berlin.de
Thu Jan 15 11:45:00 GMT 1998


I ran into a case where egcs 1.0.1 destroys a temporary object before
the enclosing expression is complete. I believe this violates section
12.2 of the 1995 C++ draft.

Regards,
Martin

Compiler version:
Reading specs from /vol/troubadix-vol2/gnu/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.90.23/specs

Test case:
#include <iostream.h>

int bug=0;
int called=0;

class X {
	int i;
public:
	X(int n);
	~X();
	void f();
	X* adr() {return this;}
};

X::X(int n):i(n){}
X::~X(){
  if(!called)bug=1;
}

void X::f(){
  called=1;
}

struct F{
  X* p1;
  F(X* p);
  ~F(){delete p1;}

};

F::F(X* p):p1(p){}

void f(F* p)
{
	p->p1->f();
}

int main()
{
	f(new F(X(1).adr()));
	if(bug)
		cout<<"FAIL"<<endl;
	else
		cout<<"PASS"<<endl;
}



More information about the Gcc-bugs mailing list