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: nob...@puremagic.com
        ReportedBy: sandf...@jhu.edu


--- Comment #0 from Rob Jacques <sandf...@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: -------

Reply via email to