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

Mathias Lang <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]
                   |                            |m
           Hardware|x86_64                      |All
            Summary|out doesn't call opAssign() |Identity opAssign not
                   |                            |called on out parameters
                 OS|Linux                       |All

--- Comment #5 from Mathias Lang <[email protected]> ---
Note: Your `opAssign` is not an identity `opAssign`
(http://dlang.org/spec/struct.html#assign-overload), so it wouldn't be called
in any copying situation.

Correct test code:

```
import std.stdio;

void foo(out Test x) {
    writeln("x.n = ", x.n);
}

struct Test {
    int n;
    ~this() {
        writeln("~this()");
    }
    ref Test opAssign(Test val) {
        writefln("opAssign(%s)", val);
        return this;
    }
}

void main() {
    Test t;
    foo(t);
    writeln("done");
}
```

And this doesn't call `opAssign` either (same output).

What should happen here:
- The destructor should be called if no `opAssign` is defined, because the
compiler provides an elaborate `opAssign` when it sees a struct with a dtor or
postblit being copied.
- If an identity `opAssign` is defined, it should be called.

I'll change the title, because `out` can be contract as well.

--

Reply via email to