www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5082] New: delegate alias parameters are silently accepted inside structs. limits most of std.algorithm, etc.

reply d-bugmail puremagic.com writes:
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



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: -------
Oct 19 2010
next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jun 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5082




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: -------
Jun 12 2012
prev sibling parent d-bugmail puremagic.com writes:
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: -------
Jun 12 2012