www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6048] New: struct methods included in .tupleof

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

           Summary: struct methods included in .tupleof
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: robert octarineparrot.com



22:17:13 BST ---
The following code:
----
template canPersist(T) 
{
    enum canPersist = canPersist!(T, typeof(T.tupleof));
}

template canPersist(T, U...) 
{
    enum canPersist = canPersist!(T, U[0]) && canPersist!(T, U[1..$]);
}

template canPersist(T, U : U*)
{
    static assert(0, "is this a bug in dmd? methods shouldn't be in .tupleof");
}

void main()
{
    struct Test
    {
        bool opEquals(ref const Test other) const
        {
            return true;
        }
    }
    enum foo = canPersist!Test;
}
----
Fails to compile with:
----
prog.d(13): Error: static assert  "is this a bug in dmd? methods shouldn't be
in .tupleof"
prog.d(3):        instantiated from here: canPersist!(Test,void*)
prog.d(25):        instantiated from here: canPersist!(Test)
----

Adding additional methods to Test has no effect (they don't show up in
.tupleof), same goes for normal fields (providing you add template
canPersist(T, U) { enum canPersist = true; }). Iterating over
typeof(Test.tupleof) in main() does not give the void* type.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 23 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6048


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm gmail.com



This is expected. An inner struct contains a context pointer to the scope. Use
'static struct' and that 'void*' member will be gone. To illustrate:

-----------------------------------
void main() {
    struct S{ void a(){} }
    static struct T{ void b(){} }
    pragma(msg, S.tupleof);
    pragma(msg, T.tupleof);
}
-----------------------------------
tuple((S).this)
tuple()
-----------------------------------

(Although changing that struct to 'static struct' causes a forward-reference
error)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 23 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6048


Robert Clipsham <robert octarineparrot.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



23:58:22 BST ---
Thank you. I'd forgotten that local structs aren't POD.

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