Lifetime bug in temporaries

Marc Espie
Wed Mar 25 09:52:00 GMT 1998

I've solved my problem (thanks Gaby & M. Cosak).
The problem is here:

>template<class U>class Expr
>   {
>   const U &a;
This is the line that makes it leggit for the compiler to get rid
of a temporary even though this ref still exists in:

>template<class U, class V>inline Expr<SumExpr<Vector<U>, Vector<V> > >
>operator+(const Vector<U> &a, const Vector<V> &b)
>   {
>   return make_expr(make_sum(a, b));
>   }

I've managed to solve the problem using actual copies in Expr and SumExpr.
This leads to introducing a VHandle class to avoid copying Vectors. This
one doesn't cause any trouble as the only Vectors I have are not temporaries.

I'm still in the process of looking at the code and checking optimizations.
This does seem like a case where egcs-current on alpha with haifa performs
significantly better than egcs-1.0.2 on m68k without haifa (constructors
of Expr<SumExpr<...>> do vanish completely).

More information about the Gcc-bugs mailing list