Bug 10510 – enforce can't take an extern(C) function to call
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-30T06:52:00Z
Last change time
2013-07-01T11:09:37Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2013-06-30T06:52:46Z
-----
import std.exception;
import core.exception;
import core.stdc.stdlib;
void foo() { }
extern(C) void cFoo() { }
void main()
{
auto p1 = enforce(malloc(10), &foo);
auto p2 = enforce(malloc(10), &cFoo); // error
// example use-case
// auto p = enforce(malloc(10), &onOutOfMemoryError);
}
-----
The constraint on enforce is:
-----
if (is(Dg : void delegate()) || is(Dg : void function()))
-----
I guess we need some kind of trait to fake the calling convention to be D in order to compare it against the type, such as:
-----
if (is(ToExternD!Dg : void delegate()) || is(ToExternD!Dg : void function()))
-----
Comment #1 by andrej.mitrovich — 2013-07-01T10:41:13Z