Thread overview
[Issue 5082] New: delegate alias parameters are silently accepted inside structs. limits most of std.algorithm, etc.
Oct 20, 2010
Rob Jacques
Jun 01, 2012
Kenji Hara
Jun 12, 2012
Walter Bright
October 20, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5082

           Summary: delegate alias parameters are silently accepted inside
                    structs. limits most of std.algorithm, etc.
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: sandford@jhu.edu


--- Comment #0 from Rob Jacques <sandford@jhu.edu> 2010-10-19 20:43:48 PDT ---
First, the underlying problem is probably that delegate literals that access a user defined (not built-in) type on the stack are apparently not valid. This is may be related to issues 4217, 4333, 4312 and/or 3051. The following test case causes a compile time error:

import std.stdio;

struct myStruct { float x; }

struct Map(alias _fun) {
    typeof({ return _fun(int.init); }())  _cache;
}

void main() {
    auto temp = myStruct(0);
    auto func = (int v){return temp;};
    auto map  = Map!func();
    return;
}


Error: delegate hello.main.Map!(func).Map.__dgliteral1 cannot access frame of
function D main
Error: template instance hello.main.Map!(func) error instantiating

Now, if we modify the above to include a member function and call it, the code compiles, links and then crashes with an object.Error: Access Violation exception.

struct Map(alias _fun) {
    typeof({ return _fun(int.init); }())  _cache;  // or
    //ReturnType!_fun                     _cache;

    myStruct front(int i) {
        return _fun(i);
    }
}

void main() {
    auto temp = myStruct(0);
    auto func = (int v){return temp;};
    auto map  = Map!func();
    map.front(1);
    return;
}

If we go one step further and define cache without type inference (i.e. as a myStruct or float) this triggers a program crash and launches the windows debugger in debug mode, or an object.Error: Access Violation in release mode.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 01, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5082


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, rejects-valid
           Platform|Other                       |All
         OS/Version|Windows                     |All


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2012-06-01 07:20:58 PDT ---
https://github.com/D-Programming-Language/dmd/pull/976

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5082



--- Comment #2 from github-bugzilla@puremagic.com 2012-06-12 09:59:35 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/db33a88a267993bf51fb83fd191b816f75a53c41
fix Issue 5082 - delegate alias parameters are silently accepted inside
structs. limits most of std.algorithm, etc.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5082


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


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