[Issue 22766] New: copyEmplace does not work with copy constructor and @disable this()

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 12 11:22:04 UTC 2022


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

          Issue ID: 22766
           Summary: copyEmplace does not work with copy constructor and
                    @disable this()
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: tim.dlang at t-online.de

The following code currently does not compile:

import core.lifetime;
extern(C++) struct S
{
    @disable this();
    this(int)
    {
    }
    this(ref const(S) other)
    {
    }
}
void main()
{
    S s1 = S(1);
    S s2 = void;
    copyEmplace(s1, s2);
}

DMD prints the following error messages:

/usr/include/dlang/dmd/core/internal/lifetime.d(18): Error: static assert: 
"Cannot emplace a S because S.this() is annotated with @disable."
/usr/include/dlang/dmd/core/lifetime.d(17):        instantiated from here:
`emplaceRef!(S, S)`
/usr/include/dlang/dmd/core/lifetime.d(1251):        instantiated from here:
`emplace!(S)`
testcopyctor.d(16):        instantiated from here: `copyEmplace!(S, S)`

The default constructor should not be necessary to use the copy constructor.

--


More information about the Digitalmars-d-bugs mailing list