www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17572] New: unrestricted union erroneously invokes postblit

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

          Issue ID: 17572
           Summary: unrestricted union erroneously invokes postblit
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: wyrlon gmx.net

Expected Behavior:
prints 0
Observed Behavior:
prints 1

import std.stdio;

long post = 0;

struct Node
{
  uint val;

  this(this) { ++post; }
}

union POD(T)
{
  T val;
}

POD!Node g;

void Put(ref Node val)
{
  g = cast(POD!Node)val;
}

void main()
{
  auto x = Node(5);
  x.Put();
  post.writeln;
}

--
Jun 29 2017