www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19430] New: wrong code for `this =`

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

          Issue ID: 19430
           Summary: wrong code for `this =`
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ilyayaroshenko gmail.com

import core.atomic;
import core.stdc.stdio;
struct S
{
    int i;

    this(int i)
    {
        this.i = i;
        puts("c");
    }

    this(this)
    {
        puts("p");
    }

    ~this()
    {
        puts("d");
    }

    this(int r, int e)
    {
        this = sum(r, e);
    }

    static S sum(int r, int e)
    {
        return S(r + e);
    }
}

void main()
{
    auto c = S(1, 2);
}

output:
=================
c
d
d
=================
0 - postblits, 1 - constructor, 2 destructors

--
Nov 24 2018