Named Return Value Extension Proposal
E. Robert Tisdale
edwin@netwood.net
Mon Mar 22 20:07:00 GMT 1999
Mike Stump wrote:
> > From: "E. Robert Tisdale" <edwin@netwood.net>
>
> > It solves the problem that the egcs compiler has with function X f1(int)
> > but the function definition is entirely incompatible with ANSI C++
>
> Yes.
>
> > and it cannot solve the problem that the compiler has with function
> > X g0(X).
>
> Why not?
>
> X g0(X x) return x(x) {
> cerr << "The copy constructor may be called for g0(X)." << endl;
> return x;
> }
>
> If this doesn't scope this way now,
> I don't see it as a problem to fix it so that it does,
> and so that the semantics of it just work the way you expect.
Not quite. The function prototype is X g0(X);
which means that the compiler creates a temporary
for argument X when X g0(X) is called
then the copy constructor is called to initialize
the return value for g0(X) before entering
the body of the function.
E. Robert Tisdale <edwin@netwood.net>
More information about the Gcc
mailing list