[Issue 8655] bitfields and Typedef don't mix

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 2 16:03:57 PDT 2012


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



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2012-10-02 16:04:02 PDT ---
(In reply to comment #0)
> import std.typecons;
> import std.bitmanip;
> static import core.stdc.config;
> 
> alias Typedef!(core.stdc.config.c_ulong) c_ulong;
> 
> struct Foo
> {
>     mixin(bitfields!(
>         c_ulong, "NameOffset", 31,
>         c_ulong, "NameIsString", 1
>     ));
> }
> 
> void main()
> { }

This is a problem with mixin template Proxy(alias a). It uses a template
dispatch but doesn't take into account type properties (min, max, init..).
Although this can be fixed another issue pops up:
Error: e2ir: cannot cast result of type uint to type Typedef!(int,0)

Here's the hackish temporary workaround of Proxy.opDispatch:

template opDispatch(string name)
{
    static if (canFind(["min", "max", "init", "sizeof", "nan", "mangleof",
"stringof", "alignof", "infinity", "dig", "epsilon", "mant_dig", "max_10_exp",
"max_exp", "min_10_exp", "min_exp", "min_normal", "re", "im", "classinfo"],
name))
    {
        mixin("enum opDispatch = typeof(a)." ~ name ~ ";");
    }
    else
    static if (is(typeof(__traits(getMember, a, name)) == function))
    {
        // non template function
        auto ref opDispatch(this X, Args...)(Args args) { return
mixin("a."~name~"(args)"); }
    }
    else static if (is(typeof(mixin("a."~name))) || __traits(getOverloads, a,
name).length != 0)
    {
        // field or property function
        @property auto ref opDispatch(this X)()                { return
mixin("a."~name);        }
        @property auto ref opDispatch(this X, V)(auto ref V v) { return
mixin("a."~name~" = v"); }
    }
    else
    {
        // member template
        template opDispatch(T...)
        {
            auto ref opDispatch(this X, Args...)(Args args){ return
mixin("a."~name~"!T(args)"); }
        }
    }
}

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