www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8655] New: bitfields and Typedef don't mix

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8655

           Summary: bitfields and Typedef don't mix
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2012-09-13
20:33:42 PDT ---
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()
{ }

It's great to see we've deprecated typedef for a library solution that doesn't
work.

:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(77): Error: Cannot
interpret Typedef!(uint,0u) at compile time
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(77): Error: expression
(Typedef!(uint,0u)).opDispatch() < 0u is not constant or does not evaluate to a
bool
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(111): Error: Cannot
interpret Typedef!(uint,0u) at compile time
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(159): Error: template
instance
std.bitmanip.createAccessors!("_NameOffset_NameIsString",Typedef!(uint,0u),"NameOffset",31,0u)
error instantiating
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(213):       
instantiated from here:
createFields!("_NameOffset_NameIsString",0,Typedef!(uint,0u),"NameOffset",31,Typedef!(uint,0u),"NameIsString",1)
test.d(11):        instantiated from here:
bitfields!(Typedef!(uint,0u),"NameOffset",31,Typedef!(uint,0u),"NameIsString",1)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(77): Error: Cannot
interpret Typedef!(uint,0u) at compile time
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(77): Error: expression
(Typedef!(uint,0u)).opDispatch() < 0u is not constant or does not evaluate to a
bool
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(111): Error: Cannot
interpret Typedef!(uint,0u) at compile time
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(159): Error: template
instance
std.bitmanip.createAccessors!("_NameOffset_NameIsString",Typedef!(uint,0u),"NameIsString",1,31u)
error instantiating
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(160):       
instantiated from here:
createFields!("_NameOffset_NameIsString",31u,Typedef!(uint,0u),"NameIsString",1)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(213):       
instantiated from here:
createFields!("_NameOffset_NameIsString",0,Typedef!(uint,0u),"NameOffset",31,Typedef!(uint,0u),"NameIsString",1)
test.d(11):        instantiated from here:
bitfields!(Typedef!(uint,0u),"NameOffset",31,Typedef!(uint,0u),"NameIsString",1)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(160): Error: template
instance
std.bitmanip.createFields!("_NameOffset_NameIsString",31u,Typedef!(uint,0u),"NameIsString",1)
error instantiating
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(213):       
instantiated from here:
createFields!("_NameOffset_NameIsString",0,Typedef!(uint,0u),"NameOffset",31,Typedef!(uint,0u),"NameIsString",1)
test.d(11):        instantiated from here:
bitfields!(Typedef!(uint,0u),"NameOffset",31,Typedef!(uint,0u),"NameIsString",1)
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(213): Error: template
instance
std.bitmanip.createFields!("_NameOffset_NameIsString",0,Typedef!(uint,0u),"NameOffset",31,Typedef!(uint,0u),"NameIsString",1)
error instantiating
test.d(11):        instantiated from here:
bitfields!(Typedef!(uint,0u),"NameOffset",31,Typedef!(uint,0u),"NameIsString",1)
test.d(11): Error: template instance
std.bitmanip.bitfields!(Typedef!(uint,0u),"NameOffset",31,Typedef!(uint,0u),"NameIsString",1)
error instantiating

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 13 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8655



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich 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: -------
Oct 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8655


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid


--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2013-03-11 20:19:44 PDT ---
https://github.com/D-Programming-Language/phobos/pull/1200

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 11 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8655


Alex Rønne Petersen <alex lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alex lycus.org
         Resolution|                            |FIXED


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