digitalmars.D.bugs - [Issue 12871] New: inner function returning pointer to outer context
- via Digitalmars-d-bugs (31/31) Jun 06 2014 https://issues.dlang.org/show_bug.cgi?id=12871
https://issues.dlang.org/show_bug.cgi?id=12871 Issue ID: 12871 Summary: inner function returning pointer to outer context local rejected Product: D Version: D2 Hardware: x86 OS: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P1 Component: DMD Assignee: nobody puremagic.com Reporter: schveiguy yahoo.com When writing an inner function, or lambda, that will not escape a local for that function's scope, but instead escapes a local for the enclosing scope, the compiler rejects it with the message "Error: escaping reference to local" Example: void foo() { int a; int *dg(){return &a;} } Clearly, a will not escape its scope through dg. Such a function may be used to modularize parts of the function, and so should not be flagged as invalid. If the delegate is returned, it should create a closure anyway. Such constructs are very important to get right because the expected way to apply certain attributes such as trusted to an expression inside a safe function are via a lambda expression. --
Jun 06 2014