[Issue 21586] New: Struct dtor is called twice if struct is created inside ternary operator

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 26 22:27:45 UTC 2021


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

          Issue ID: 21586
           Summary: Struct dtor is called twice if struct is created
                    inside ternary operator
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: temtaime at gmail.com

import std.stdio;

struct S
{
        this(int arg)
        {
                a = arg;
                writeln(`this`);
        }

    ~this()
    {
        writeln(`~this `, a);
    }

        int a;
}

void main()
{
        auto s = true ? S(1) : S(0);
}

Outputs:
this
~this 1
~this 1

Should:
this
~this 1

--


More information about the Digitalmars-d-bugs mailing list