[Issue 23416] Difference DMD/GDC: Error: non-constant expression `& foo`
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Oct 15 00:47:20 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23416
--- Comment #2 from kdevel <kdevel at vogtner.de> ---
This code should compile and pass its unittest:
```post2.d
import std.stdio;
struct S {
void function () fp = &foo;
void foo ()
{
__PRETTY_FUNCTION__.writeln;
fp = (&bar).funcptr;
}
void bar ()
{
__PRETTY_FUNCTION__.writeln;
fp = (&foo).funcptr;
}
auto fun () // invocation helper
{
void delegate () dg;
dg.ptr = &this;
dg.funcptr = fp;
return dg ();
}
}
unittest {
S s;
s.fun;
s.fun;
}
```
$ dmd -O -unittest -main -run post2
post2.d(3): Error: non-constant expression `& foo`
But this code should compile and pass:
$ gdc -O -funittest -fmain post2.d -o post2 && ./post2
void post2.S.foo()
void post2.S.bar()
1 modules passed unittests
--
More information about the Digitalmars-d-bugs
mailing list