www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20712] New: Struct construction/assignment in static


          Issue ID: 20712
           Summary: Struct construction/assignment in static constructors
                    is broken
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: maxsamukha gmail.com

import std.stdio;

struct S {
    this(int x) {

    ref S opAssign(ref const S s) {
        return this;

    ~this() {

S s;
static this() {
    s = S(1); // (a)
    s = S(1); // (b)
    auto s2 = S(1);
    s = s2; // (c)

void main()

(a) Constructor is correctly called on the "branded" struct.

(b) Bug: s is "branded" and constructed again. The original value doesn't get
destructed. A correct behavior would be to try opAssign and fail because of the
rvalue-to-ref mismatch.

(c) Bug: s2 is simply blitted to s. A correct behavior would be to call

Mar 31 2020