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

--- Comment #49 from Steven Schveighoffer <[email protected]> ---
On discord, we worked out a case where the compiler is moving a struct and not
calling any opPostMove or other features (copy constructor, postblit, etc):

```d
import std.stdio;
struct S{
    S* ptr;
    this(int dummy) {ptr = &this;}
    this(this) {ptr = &this;}

    void opPostMove(const ref S oldLocation) nothrow {
        ptr = &this;
    }
}

void foo(S s){
    assert(&s == s.ptr); // fails
}
S bar(){
    auto s=S(1);
    auto t=S(1);
    if(true){ return t; }
    return s;
}
void main(){ foo(bar()); }
```

So there is still a need for the compiler to be aware of opPostMove.

In this example, the return from bar cannot be NRVO optimized, and so a copy is
made and the postblit called. Then in the call to foo, the return value of bar
is moved into the parameter for foo.

--

Reply via email to