[cxx-abi-dev] Transfer modes for parameters and return values

David Vandevoorde daveed at edg.com
Wed Jun 3 22:39:18 UTC 2009


On Jun 3, 2009, at 5:26 PM, Jason Merrill wrote:

> David Vandevoorde wrote:
>> Hello again,
>> In 3.1.1 and 3.1.4, the ABI specifies that "by value" class type  
>> parameters and class type return values are passed via the address  
>> of a reference if the class type has
>>    (a) a nontrivial destructor, or
>>    (b) a nontrivial copy constructor.
>> Should we now also add to that:
>>    (c) a (nontrivial) move constructor
>> ?
>
> I'm not sure.  We need to pass by reference in the case of a  
> nontrivial copy constructor because it's invalid to do a bitwise  
> copy in that case.  We need to do it in the case of a nontrivial  
> destructor so that the caller can control when the destructor is run  
> depending on copy elision.  Neither of those really applies to the  
> move constructor.


Consider the following example:

	struct S {
	  S();
	  S(S&&);
	private:
	  S(S const&) = default;    // Trivial copy constructor.
	};

	void f(S);

	int main() {
	  f(S());
	}

My understanding is that the move constructor must be called to pass  
the argument directly to f, and that the trivial copy constructor  
cannot be called as an extra step in that case.  (I.e., although this  
is called "copy initialization", it's really very much like default  
initialization.)

No?

	Daveed




More information about the cxx-abi-dev mailing list