The C++11 standard states that, if the conditions for copy elision are met (§12.8/31
), the implementation shall treat a return
ed local lvalue varia
When returning a subobject you can't elide its construction. Think of it this way: move and copy elision essentially amount to constructing the object in the place it would eventually be moved or copied to. This works for complete objects because there will be the appropriate space be set aside. It doesn't work with subobjects because you would construct the enclosing object. Even if this has the same size as the subobject, i.e. there is enough space, the enclosing object gets destroyed and may do funny things to the subobjects.
Effectively, this means that construction of the subject cannot be elided.