[Issue 10875] New: Introduce functionLinkageType to mirror functionLinkage with an enum

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 23 04:51:29 PDT 2013


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

           Summary: Introduce functionLinkageType to mirror
                    functionLinkage with an enum
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          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-08-23 04:51:27 PDT ---
Currently std.traits.functionLinkage returns the linkage type, but it returns
it as a string. So if you have generic code, you might end up writing code like
so:

-----
import std.traits;

extern(C) void func()
{
}

void main()
{
    enum linkage = functionLinkage!func;

    static if (linkage == "c")
    {
    }
    else
    static if (linkage == "D")
    {
    }
}
-----

Unfortunately there's a bug here, there is no lowercase "c" linkage type, only
"C". It would be safer if functionLinkage returned an enum. 

But since it's too late to change the return type, I propose we introduce an
enum version:

-----
import std.traits;

extern(C) void func()
{
}

void main()
{
    // new trait which returns a LinkageType enum instance
    enum linkage = functionLinkageType!func;

    static if (linkage == LinkageType.c)
    {
    }
    else
    static if (linkage == LinkageType.d)
    {
    }
}
-----

This will also allow a user to generate code by using EnumMembers on the
LinkageType enum.

-- 
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