[Issue 20695] Copy constructor disable default struct constructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 26 08:03:27 UTC 2020


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

Mike Parker <aldacron at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aldacron at gmail.com

--- Comment #3 from Mike Parker <aldacron at gmail.com> ---
It's always been the case that implementing opCall or a constructor disables
struct literals and initializers (except the default initializer T()), but it's
not currently in the spec (I'm sure it was at one time).

>From TDPL 7.1.3.1:

"The presence of at least one constructor disables all of the field-oriented
constructors discussed above..."

And by "field-oriented constructors", he's referring to literals and
initializers. The example:

```
struct Test {
    double a = 0.4;
    double b;
    this(double b) {
        this.b = b;
    }
}

auto t1 = Test(1.1, 1.2); // Error
    // No constructor matches Test(double, double)
static Test t2 = {0.0, 1.0}; // Error
    // No constructor matches Test(double, double);
```

The spec needs to be updated.

--


More information about the Digitalmars-d-bugs mailing list