[Issue 15869] New: RVO can overwrite argument
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Apr 3 21:08:58 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15869
Issue ID: 15869
Summary: RVO can overwrite argument
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: yshuiv7 at gmail.com
Test case:
struct Set {
void insert(ulong v) {
aa[v] = true;
}
@disable this(this);
bool[ulong] aa;
}
auto clobber(ref Set x, ref Set o) {
Set ret; // <- This overwrites x
ret.aa = x.aa; // <- Now x.aa is empty
return ret;
}
struct XX {
Set a, b, tmp;
this(int n) {
a.insert(1);
//a.aa[1] = true; <- Swap above line with this doesn't trigger the bug
tmp = a.clobber(b);
a = a.clobber(b);
}
}
void main(){
import std.stdio;
XX xx = XX(0);
writeln(xx.a.aa.length); // 0
writeln(xx.tmp.aa.length); // 1
}
--
More information about the Digitalmars-d-bugs
mailing list