www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15662] New: Cannot move struct with defined opAssign due to


          Issue ID: 15662
           Summary: Cannot move struct with defined opAssign due to
                     disabled post-blit
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: matt.elkins gmail.com

Given the following definition:

import std.algorithm;

struct ResourceHandle(T, alias Deleter, T Default = T.init)
    // Constructors/Destructor
    this(T handle) {m_handle = handle;}
     disable this(this);
    ~this() {Deleter(m_handle);}

    // Operators
     disable void opAssign(ref ResourceHandle lvalue);
    ref ResourceHandle opAssign(ResourceHandle rvalue) {swap(m_handle,
rvalue.m_handle); return this;}

    // Methods
     property inout(T) handle() inout {return m_handle;}
     property T handle(T handle) {Deleter(m_handle); m_handle = handle; return
    T release() {T result = m_handle; m_handle = Default; return result;}

        T m_handle = Default;

The following will generate a compile error, making it awkward to move unique

    alias RH = ResourceHandle!(uint, (uint) {});
    RH[] handles;
    handles ~= RH(5); // Compile error: ResourceHandle is not copyable because
it is annotated with  disable

See discussion at
https://forum.dlang.org/post/nnjfuqeuprcswsjjfmkl forum.dlang.org

At first I was uncertain whether this was a bug or by design, but Andrei
Alexandrescu confirmed the bug status in the linked discussion.

Feb 08 2016