This is the mail archive of the
mailing list for the GCC project.
Re: Lifetime bug in temporaries
- To: egcs-bugs at cygnus dot com
- Subject: Re: Lifetime bug in temporaries
- From: espie at quatramaran dot ens dot fr (Marc Espie)
- Date: Wed, 25 Mar 1998 17:11:42 +0100
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).