[Issue 13247] New: switch doesn't work with pointers to functions. Also casting pointers to functions to integers doesn't work during compilation.
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Aug 3 13:00:58 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13247
Issue ID: 13247
Summary: switch doesn't work with pointers to functions. Also
casting pointers to functions to integers doesn't work
during compilation.
Product: D
Version: D2
Hardware: x86
OS: Mac OS X
Status: NEW
Severity: enhancement
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: andrei at erdani.com
Consider:
void fun(T)() {}
enum A
{
_1 = &fun!int,
_2 = &fun!string,
_3 = &fun!double,
}
void main(string[] args) {
A a = A._1;
final switch (a)
{
case A._1: writeln("eh"); break;
case A._2: writeln("meh"); break;
case A._3: writeln("neh"); break;
}
}
The enum works but the switch doesn't. Trying to force to integrals:
void fun(T)() {}
enum A
{
_1 = cast(size_t) &fun!int,
_2 = cast(size_t) &fun!string,
_3 = cast(size_t) &fun!double,
}
void main(string[] args) {
A a = A._1;
final switch (a)
{
case A._1: writeln("eh"); break;
case A._2: writeln("meh"); break;
case A._3: writeln("neh"); break;
}
}
Now the enum doesn't compile. Would be great if at least one of these worked.
--
More information about the Digitalmars-d-bugs
mailing list