Let's say I have a function that looks like this:
SomeObject copy_maybe(bool make_new, const SomeObject& def)
{
if (make_new)
return SomeObject();
else
return def;
}
And I call it like this:
SomeObject obj;
obj = copy_maybe(true, obj);
Without copy elision, this will clearly always result in a copy to obj
from a temporary created in copy_maybe
. However, with copy elision/RVO, is it possible that the copy will happen from obj
to obj
?
More specifically, under these (or similar) conditions, is it possible in a copy operator (void operator=(SomeObject const &other)
) that this
and &other
will be the same due to copy elision?
I created a test on Ideone, and it returns separate addresses, but I just want to make sure that this behavior is defined by the spec.