[cxx-abi-dev] Transfer modes for parameters and return values
Jason Merrill
jason at redhat.com
Thu Jun 4 21:34:15 UTC 2009
David Vandevoorde wrote:
> Note that if I'm correct, there is already a bug in the ABI because a
> class like:
>
> struct S {
> S(int);
> };
> void f(S);
>
> today is passed "by trivial copy" in the function f (according to the
> ABI). However, my understanding is that in
>
> int main() {
> f(3);
> }
>
> no copy constructor should be called (even "conceptually") for the
> argument transfer (i.e., despite it being a "copy initialization" it
> behaves like a "direct initialization).
No. To copy-initialize the parameter of f, we first convert 3 to S
using the constructor, then construct the parameter using that temporary
S as an argument, which invokes the (trivial) copy constructor.
However, I think you are right about your earlier move constructor
example: since the argument S() has type S already, we don't do the
two-step initialization, so we can't do a (trivial) copy afterward.
This line of reasoning also applies to any other constructor which can
be called with an argument of the that class or a derived class, but I
think before rvalue references it was impossible to write an alternative
constructor which would ever be preferred over the implicitly declared
copy constructor for an argument of that class type.
So now I think we do need your suggested change.
Jason
More information about the cxx-abi-dev
mailing list