This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Lifetime bug in temporaries


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).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]