www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22510] New: Structs with copy constructor can not be heap

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

          Issue ID: 22510
           Summary: Structs with copy constructor can not be heap
                    allocated with default constructor
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: omerfirmak gmail.com

import std;

struct S
{
        int b;

     disable this(this);
    this (scope ref inout S) inout
    {
        this.b = b;
    }
} 

void main()
{
        auto scoped_s = S(4);
        auto heap_s = new S(42);
}

-----------------------------------

`auto heap_s = new S(42)` line fails with the following error;

onlineapp.d(17): Error: copy constructor `onlineapp.S.this(ref inout(S)
_param_0) inout` is not callable using argument types `(int)`
onlineapp.d(17):        cannot pass rvalue argument `42` of type `int` to
parameter `ref inout(S) _param_0`

--
Nov 14 2021