[Issue 20025] alias this combined with a copy constructor seems to lead to undefined behaviour.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jul 4 08:16:10 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20025
Simen Kjaeraas <simen.kjaras at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |simen.kjaras at gmail.com
--- Comment #1 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
A slightly more elucidating example:
struct B {
static int value = 77;
alias value this;
int i = 13;
this(ref B rhs) { }
}
void test(ref int x, ref B b) {
import std.stdio : writeln;
writeln("x: ", &x, " = ", x);
writeln("b: ", &b);
}
unittest {
B b;
test(b, b);
}
x is now consistently 13, and &x == &b. IOW, alias this is somehow forgetting
that value is a static field, and treats it as non-static.
--
More information about the Digitalmars-d-bugs
mailing list