<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Jan 16, 2013, at 13:12 , Krzysztof Parzyszek <<a href="mailto:kparzysz@codeaurora.org">kparzysz@codeaurora.org</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">On 1/16/2013 3:04 PM, reed kotler wrote:<br><blockquote type="cite"><br>This seems illogical to me. It does not call the copy constructor in<br>5.cpp but in 6.cpp it tails<br>to compile because it can't find a valid copy constructor.<br></blockquote><br>IIRC, according to the standard, this<br>  B b = f(1);<br>is equivalent to<br>  B b(f(1));<br><br>I suppose the compiler refuses to treat f(1) as an object of type B&, since it's a temporary.  Again, if I remember things correctly...<br></blockquote></div><br><div>Right, the standard requires that the copy constructor <i>exist,</i> but allows the copy itself to be elided. In C++11, a move constructor would work here as well.</div><div><br></div><div>C++11 [class.temporary]p1: Temporaries of class type are created in various contexts: ...returning a prvalue (6.6.3)…</div><div><br></div><div>C++11 [class.copy]p31: When certain criteria are met, an implementation is allowed to omit the copy/move construction of a class object...in a return statement in a function with a class return type, when the expression is the name of a non-volatile automatic object (other than a function or catch-clause parameter) with the same cv- unqualified type as the function return type, the copy/move operation can be omitted by constructing the automatic object directly into the function’s return value, [and] when a temporary class object that has not been bound to a reference (12.2) would be copied/moved to a class object with the same cv-unqualified type, the copy/move operation can be omitted by constructing the temporary object directly into the target of the omitted copy/move</div><div><br></div><div>Jordan</div></body></html>