This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH: PR 9965
On 06 Mar 2003 22:41:54 -0800, Mark Mitchell <mark at codesourcery dot com> wrote:
> On Thu, 2003-03-06 at 20:04, Jason Merrill wrote:
>> We don't have to make a copy at all. The old code just forced the Derived
>> to live as long as as b.
>
> The same thing happens here: the TARGET_EXPR for the call gets bound to
> the new VAR_DECL, which is another way of saying that no copy gets made.
> That's exactly the same technique that cvt.c used; I just moved the
> code.
The problem is that previously (in build_up_reference), the VAR_DECL was
initialized before the derived->base conversion, and now it's initialized
after the conversion. But that requires a copy that we didn't need
before.
> But, if you can find a place where we create more temporaries than we
> used to, then I take it all back and I'll fix the problem.
int c;
struct Base {
Base() {}
Base(const Base &) { ++c; }
Base & operator = (const Base &);
};
struct Derived : public Base {};
const Base &b = Derived();
int main()
{
return c;
}
With 3.2, this returns 0. With cvs head, it returns 1.
Jason