www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22766] New: copyEmplace does not work with copy constructor

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 puremagic.com
          Reporter: tim.dlang 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.

--
Feb 12 2022