Copy constructor hell

9il ilyayaroshenko at gmail.com
Wed May 8 12:47:10 UTC 2019


On Wednesday, 8 May 2019 at 11:19:02 UTC, 9il wrote:
> On Wednesday, 8 May 2019 at 09:05:48 UTC, RazvanN wrote:
>> On Wednesday, 8 May 2019 at 03:18:14 UTC, 9il wrote:
>>> [...]
>>
>> What is the signature of the copy constructor that you have 
>> defined? Have you tried the this(inout typeof(this)) inout one?
>
> The copy constructor is autogenerated for S.
>
> Check: https://run.dlang.io/is/3sJTrf
> -------
> struct T
> {
>     int i;
>     this(ref return scope inout typeof(this) src)
>         inout @safe pure nothrow @nogc
>     {
>         i = src.i;
>     }
> }
>
> struct S
> {
>     T t;
> }
>
> auto bar(T a)
> {
> 	S(a);
> }
> -------
>
> onlineapp.d(18): Error: copy constructor onlineapp.S.this(ref 
> inout(S) p) inout is not callable using argument types (T)
> onlineapp.d(18):        cannot pass argument a of type T to 
> parameter ref inout(S) p

It introduces regression for Phobos as well. For example,

`DontCallDestructorT(arg)` is no longer possible for T arg.

---
struct Nullable(T)
{
     private union DontCallDestructorT
     {
         T payload;
     }
  ....
}


More information about the Digitalmars-d mailing list