Thread overview
[Issue 20695] Copy constructor disable default struct constructor
Mar 26, 2020
RazvanN
Mar 26, 2020
RazvanN
Mar 26, 2020
Mike Parker
Mar 26, 2020
Mathias LANG
Mar 26, 2020
Mathias LANG
Mar 26, 2020
RazvanN
Jan 14, 2021
Dlang Bot
Jan 17, 2021
Dlang Bot
March 26, 2020
https://issues.dlang.org/show_bug.cgi?id=20695

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
This is not related to copy constructors:

struct K
{
    int a;
    string b;
    this(int, int, int) {}
}

void main()
{
    K s = K(7, "gigi");
}

It seems that once you define a constructor, you are not able to use the default constructor.

--
March 26, 2020
https://issues.dlang.org/show_bug.cgi?id=20695

--- Comment #2 from RazvanN <razvan.nitu1305@gmail.com> ---
I can't find anything in the spec regarding this aspect.

--
March 26, 2020
https://issues.dlang.org/show_bug.cgi?id=20695

Mike Parker <aldacron@gmail.com> changed:

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

--- Comment #3 from Mike Parker <aldacron@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.

--
March 26, 2020
https://issues.dlang.org/show_bug.cgi?id=20695

--- Comment #4 from Mathias LANG <pro.mathias.lang@gmail.com> ---
> It's always been the case that implementing opCall or a constructor disables struct literals and initializers

`opCall` does not disable literals. And it technically *hides* constructors, I'm sure there are some convoluted way to show it.

> This is not related to copy constructors: [...]

I'm well aware of the disappearance of default ctors in the presence of a single definition. While I would like for us to have a way to control it, a la "this() = default" (from C++), copy ctors are not *regular* ctors, and I don't think they should disable the default constructors.

--
March 26, 2020
https://issues.dlang.org/show_bug.cgi?id=20695

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86                         |All
                 OS|Mac OS X                    |All
           Severity|enhancement                 |normal

--
March 26, 2020
https://issues.dlang.org/show_bug.cgi?id=20695

--- Comment #5 from RazvanN <razvan.nitu1305@gmail.com> ---
(In reply to Mathias LANG from comment #4)
> > It's always been the case that implementing opCall or a constructor disables struct literals and initializers
> 
> `opCall` does not disable literals. And it technically *hides* constructors, I'm sure there are some convoluted way to show it.
> 
> > This is not related to copy constructors: [...]
> 
> I'm well aware of the disappearance of default ctors in the presence of a single definition. While I would like for us to have a way to control it, a la "this() = default" (from C++), copy ctors are not *regular* ctors, and I don't think they should disable the default constructors.

Actually, copy constructors behave exactly as normal constructors, except that they may be called implicitly in some situations.

--
January 14, 2021
https://issues.dlang.org/show_bug.cgi?id=20695

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
@RazvanN7 created dlang/dmd pull request #12132 "Fix Issues 20695, 21547 - CpCtor disables default construction + Struct initializers are disabled wrongfully" fixing this issue:

- Fix Issues 20695, 21547 - CpCtor disables default construction + Struct initializers are disabled wrongfully

https://github.com/dlang/dmd/pull/12132

--
January 17, 2021
https://issues.dlang.org/show_bug.cgi?id=20695

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #12132 "Fix Issues 20695, 21547 - CpCtor disables default construction + Struct initializers are disabled wrongfully" was merged into master:

- b61df05dd3d5d9792452c496d07fe04f2df12993 by RazvanN7:
  Fix Issues 20695, 21547 - CpCtor disables default construction + Struct
initializers are disabled wrongfully

https://github.com/dlang/dmd/pull/12132

--