[Issue 10510] New: enforce can't take an extern(C) function to call

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jun 30 06:52:47 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10510

           Summary: enforce can't take an extern(C) function to call
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-06-30 06:52:46 PDT ---
-----
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()))
-----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list