www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20406] New: Copy constructor requires default constructor

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

          Issue ID: 20406
           Summary: Copy constructor requires default constructor
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: Bastiaan Veelo.net

```
struct S
{
         disable this();
        this(int) {}
        this(ref S other) {}
}

void foo(S s) {}

S s = S(3);
foo(s);
```

Fails compilation with a message like "Error: variable
`onlineapp.main.__copytmp112` default construction is disabled for type `S`"

Either removing the copy constructor or enabling the default constructor makes
this work.

Note that this seems to be only an issue for parameter passing, explicit
initializations still work fine for the above definition of S:

S s2 = s;

--
Nov 18 2019