www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21204] New: Error in generated copy constructor gives

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 puremagic.com
          Reporter: snarwin+bugzilla 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.

--
Aug 28 2020