[Issue 23444] New: Can't append non-copyable struct value to an array

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Oct 29 15:13:24 UTC 2022


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

          Issue ID: 23444
           Summary: Can't append non-copyable struct value to an array
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

As of DMD 2.100.2, the following program fails to compile:

---
struct NoCopy
{
    @disable this(this);
}

void main()
{
    NoCopy[] a;
    a ~= NoCopy(); // error
}
---

The error message is:

---
bug.d(9): Error: struct `bug.NoCopy` is not copyable because it has a disabled
postblit
---

However, this error is spurious. The program below compiles without errors and
produces no output when run, because the postblit is not actually called at
runtime:

---
struct NoCopy
{
    this(this)
    {
        import std.stdio;
        writeln("copied");
    }
}

void main()
{
    NoCopy[] a;
    a ~= NoCopy(); // ok; no output
}
---

--


More information about the Digitalmars-d-bugs mailing list