Compiles with LDC 1.18 release, but segfaults.
Fails to compile with DMD github HEAD.
import std.stdio: writeln;
class Frop { }
class Foo {
Frop frop1;
}
class Bar: Foo {
Frop frop0;
void boo(alias V, string VS)() {
writeln("boo: ", __traits(getMember, this, VS).stringof);
writeln("boo: ", V.stringof);
assert(V is null); // not OK for frop1
assert(__traits(getMember, this, VS) is null); // not OK for frop1
}
void zoo(alias V)() {
writeln("zoo: ", V.stringof);
assert(V is null); // not OK for frop1
}
void goo(string VS)() {
writeln("goo: ", __traits(getMember, this, VS).stringof);
assert(__traits(getMember, this, VS) is null);
}
void setup() {
assert(frop0 is null);
moo!(frop0, "frop0")(this);
moo!(frop1, "frop1")(this);
boo!(frop0, "frop0")();
goo!("frop0");
goo!("frop1");
zoo!(frop0)();
zoo!(frop1)(); // segfault with LDC -- does not compile with DMD
boo!(frop0, "frop0")();
boo!(frop1, "frop1")(); // segfault with LDC -- does not compile with DMD
}
}
void moo(alias V, string VS, L)(L l) {
import std.stdio;
writeln("moo: ", __traits(getMember, l, VS).stringof);
writeln("moo: ", V.stringof);
assert(V is null); // OK
assert(__traits(getMember, l, VS) is null); // OK
}
void main() {
Bar bar = new Bar();
bar.setup();
}
Comment #1 by moonlightsentinel — 2019-10-29T11:03:57Z
Reduced with dustmite:
class Frop {}
class Foo {
Frop frop1;
}
class Bar: Foo {
void zoo(alias V)() {
}
void setup() {
zoo!frop1;
}
}
Comment #2 by robert.schadek — 2024-12-13T19:06:02Z