[Issue 11202] Copy constructor is called instead of assignment on member

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 6 12:13:40 UTC 2018


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com

--- Comment #4 from RazvanN <razvan.nitu1305 at gmail.com> ---
opAssign for a struct is used only if it is defined for that particular struct.
If the struct defines a postblit, but not an opAssign the compiler steps in and
generates an opAssign which basically calls the postblit. The whole point of
this design is to avoid declaring both a copy constructor and a postblit when
the 2 are identical.

In this particular case, the compiler generates a postblit for T and as T does
not define an opAssign, it will generate one. This is the intended behavior.
If you want to make struct T uncopyable, you should disable its postblit 

>This isn't strictly *wrong*, its just a pretty dirty way of doing things, and I'm pretty sure it's inefficient, and it definitly defeats the purpose of having an opAssign to begin with.

It does not defeat the purpose of opAssign. Postblit and opAssign are 2
different things. Postblit is used for initialization and opAssign for copies,
however it is a feature that the compiler generates an opAssign from the
postblit when the user does not define one.

I suggest closing as wontfix.

--


More information about the Digitalmars-d-bugs mailing list