www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3909] New: toDelegate handles only a tiny subset of function pointer types

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

           Summary: toDelegate handles only a tiny subset of function
                    pointer types
           Product: D
           Version: 2.041
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: samukha voliacable.com



PST ---
Current implementation of toDelegate requires parameter and return types of the
argument to be accessible from std.functional, meaning that it won't accept
most of function pointers taking or returning instances of UDTs:

----
import std.functional;

struct S
{
}

void foo(S s)
{
}

void main()
{
    auto dg = &toDelegate(&foo);
}

Error: identifier 'S' is not defined
----

The cause is the mixed-in delegate type generated from the function pointer
type's stringof, which is invalid in the context of the template declaration.
A workaround is to avoid the stringof like this:

alias ParameterTypeTuple!(F) Params;
// mixed-in string:
alias <storage classes> ReturnType!(F) delegate(<storage classes> Params[0],
... <storage classes> Params[$ - 1]) Dg;

where <storage classes> are extracted from F's stringof (isRef, isOut, isLazy
may work too)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 08 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3909




PST ---
In the test case,

auto dg = &toDelegate(&foo);

should be

auto dg = toDelegate(&foo);

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


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha yahoo.com
         Depends on|                            |1818



I just noticed this report now.  Really, the reason this code is so poorly
designed (I wrote it, and I'll admit in hindsight that it does suck) is bug
1818.  The stupid mixin hack was a last-minute workaround for this bug and
wasn't thought through properly.  This is noted in the comments:

functional.d around line 550:

    // Workaround for DMD Bug 1818.
    mixin("alias " ~ ReturnType!(F).stringof ~
        " delegate" ~ ParameterTypeTuple!(F).stringof ~ " DelType;");

    version(none) {
        // What the code would be if it weren't for bug 1818:
        alias ReturnType!(F) delegate(ParameterTypeTuple!(F)) DelType;
    }

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




PDT ---

 I just noticed this report now.  Really, the reason this code is so poorly
 designed (I wrote it, and I'll admit in hindsight that it does suck) is bug
 1818.  The stupid mixin hack was a last-minute workaround for this bug and
 wasn't thought through properly.  This is noted in the comments:
 
 functional.d around line 550:
 
     // Workaround for DMD Bug 1818.
     mixin("alias " ~ ReturnType!(F).stringof ~
         " delegate" ~ ParameterTypeTuple!(F).stringof ~ " DelType;");
 
     version(none) {
         // What the code would be if it weren't for bug 1818:
         alias ReturnType!(F) delegate(ParameterTypeTuple!(F)) DelType;
     }
Phobos has recently acquired functionality for extracting storage classes from functions and function parameters. I haven't given it a close look but it seems to do that by parsing mangled names. Hacky but should make it possible to correctly generate function types based on other function types. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 25 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3909


Shin Fujishiro <rsinfu gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|rsinfu gmail.com            |nobody puremagic.com



---
I commited a hacky workaround in svn r1561.  Now it works with user-defined
types and function attributes (such as pure).  But I leave this bug opened
becuase the bug is not completely fixed.

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