Why postblit cannot be disabled when copy ctor is defined
Daniel Kozak
kozzi11 at gmail.com
Thu Nov 7 19:10:50 UTC 2019
On Thu, Nov 7, 2019 at 6:30 PM Fanda Vacek via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> import std.stdio;
>
> struct A
> {
> int x;
> this(ref return scope A rhs)
> {
> writeln("copy ctor: ", x);
> }
> @disable this(this) {writeln("postblit: ", x); }
> }
>
> void main()
> {
> A a;
> A b = a; // copy constructor gets called
> }
>
> I've got error: Error: struct `tst.A` is not copyable because it
> is annotated with `@disable`
>
> but it should not be used according to
> https://dlang.org/spec/struct.html#struct-postblit
>
> WARNING: The postblit is considered legacy and is not recommended
> for new code. Code should use copy constructors defined in the
> previous section. For backward compatibility reasons, a struct
> that defines both a copy constructor and a postblit will only use
> the postblit for implicit copying.
This is a bug, please fill an issue on https://issues.dlang.org/
More information about the Digitalmars-d
mailing list