Bug 5082 – delegate alias parameters are silently accepted inside structs. limits most of std.algorithm, etc.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-10-19T20:43:00Z
Last change time
2012-06-12T10:01:04Z
Keywords
pull, rejects-valid, wrong-code
Assigned to
nobody
Creator
sandford

Comments

Comment #0 by sandford — 2010-10-19T20:43:48Z
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.
Comment #1 by k.hara.pg — 2012-06-01T07:20:58Z
Comment #2 by github-bugzilla — 2012-06-12T09:59:35Z
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.