[Issue 24415] Can't call public copy constructor preceded by private template constructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 26 20:01:06 UTC 2024


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

Paul Backus <snarwin+bugzilla at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |snarwin+bugzilla at gmail.com
          Component|phobos                      |dmd
           Hardware|x86_64                      |All
            Summary|only doesn't work with      |Can't call public copy
                   |elements that have a copy   |constructor preceded by
                   |constructor                 |private template
                   |                            |constructor

--- Comment #2 from Paul Backus <snarwin+bugzilla at gmail.com> ---
This is a compiler bug. The presence of a private templated constructor earlier
in the overload set prevents the public copy constructor from being called from
another module.

Minimal reproduction:

--- lib.d
module lib;

struct S
{
    int n;
    private this()(int n) { this.n = m; }
    this(ref inout S other) inout {}
}
--- app.d
module app;

import lib;

void main()
{
    S a;
    auto b = a;
}
---

Which produces this error message when compiled:

---
app.d(8): Error: no property `__ctor` for `b` of type `lib.S`
lib.d(3):        struct `S` defined here
---

Note that the bug is order-dependent. If the copy constructor is moved above
the private templated constructor, the example compiles successfully.

--


More information about the Digitalmars-d-bugs mailing list