[Issue 5082] New: delegate alias parameters are silently accepted inside structs. limits most of std.algorithm, etc.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Oct 19 20:44:29 PDT 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 at puremagic.com
ReportedBy: sandford at jhu.edu
--- Comment #0 from Rob Jacques <sandford at 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: -------
More information about the Digitalmars-d-bugs
mailing list