[Issue 15869] RVO can overwrite argument

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Apr 4 10:37:48 PDT 2016


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

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |ag0aep6g at gmail.com
           Hardware|x86_64                      |All
                 OS|Linux                       |All
           Severity|enhancement                 |normal

--- Comment #1 from ag0aep6g at gmail.com ---
Slightly reduced:
----
struct Set {
    @disable this(this);
    int value = 0;
}
Set clobber(Set* a) {
    Set ret; // <- This overwrites *a, i.e. &ret is the same as a
    ret.value = a.value; // <- Now a.value is 0
    return ret;
}
struct XX {
    Set a = Set(1);
    this(int n) {
        a = clobber(&a);
    }
}
void main(){
    XX xx = XX(0);
    assert(xx.a.value == 1); /* fails */
}
----

--


More information about the Digitalmars-d-bugs mailing list