Is NRVO part of the spec?

Peter Alexander via Digitalmars-d digitalmars-d at puremagic.com
Sat Feb 7 07:08:10 PST 2015


On Saturday, 7 February 2015 at 14:46:55 UTC, Daniel Murphy wrote:
> NRVO isn't required for correct semantics, as structs can be 
> moved with bitcopy.

Yes, you're right. I suppose what I mean is that it should be 
guaranteed that returning a local Lvalue by value should always 
be moved to the caller destination, rather than copied then 
destroyed.

S foo() {
   S s;
   return s;
}
S s = foo();  // no destructors or postblits should be called here

The spec needs to guarantee this, otherwise unary 
std.algorithm.move isn't guaranteed to work for non-copyable 
types.


More information about the Digitalmars-d mailing list