Should this work or a bug in compiler?
apz28
home at home.com
Sat Nov 7 03:46:47 UTC 2026
struct S
{
int x;
ref S byRef() return
{
return this;
}
}
void main()
{
import std.conv : to;
import std.stdio : writeln;
S s;
s.x = 1;
auto s2 = s.byRef();
s2.x = 2;
writeln(&s, " vs ", &s2);
assert(s2.x == 2, s2.x.to!string());
assert(s.x == 2, s.x.to!string());
}
Output from v2.113
7FFF27E25958 vs 7FFF27E2595C
core.exception.AssertError at onlineapp.d(23): 1
----------------
??:? _d_assert_msg [0x5ef4a93a89d0]
./onlineapp.d:23 _Dmain [0x5ef4a93841c7]
More information about the Digitalmars-d-learn
mailing list