[Issue 21204] New: Error in generated copy constructor gives confusing message

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 28 13:18:23 UTC 2020


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

          Issue ID: 21204
           Summary: Error in generated copy constructor gives confusing
                    message
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

Example program:

---
struct A
{
    this(ref A other) {}
}

struct B
{
    A a;
}

void example()
{
    B b1;
    B b2 = b1;
}
---

Attempting to compile this results in the following error message:

onlineapp.d(14): Error: copy constructor onlineapp.B.this cannot be used
because it is annotated with @disable

This is confusing, because there is no `@disable` annotation in the source
code. The actual problem is that the compiler attempted to generate an `inout`
copy constructor for B, but failed, because A's copy constructor only works for
mutable instances of A.

--


More information about the Digitalmars-d-bugs mailing list