[Issue 15848] Identity opAssign not called on out parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 7 09:05:32 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=15848

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305 at gmail.com
         Resolution|---                         |WORKSFORME

--- Comment #7 from RazvanN <razvan.nitu1305 at gmail.com> ---
I think that the behavior exhibited here is correct.

The spec for out parameters says: "The argument must be an lvalue, which will
be passed by reference and initialized upon function entry with the default
value (T.init) of its type."

Although it is not clearly stated, the way I read it is that the compiler
simply blits T.init over the argument and then it passes a reference to it. No
copy constructor and no assignment operator are called. Therefore, the
destructor is called only for `t` to destroy the object in the main function.

This is correct behavior and much more efficient as it avoids a copy
constructor/assignment call and a destructor call.

I'm going to tentatively close this as WORKSFORME. But please reopen if I am
missing something.

--


More information about the Digitalmars-d-bugs mailing list