digitalmars.D - Struct with lambda argument causes segfault at runtime
- H. S. Teoh via Digitalmars-d (22/22) Aug 09 2014 Here's a lovely Saturday morning exercise for you D aficionados out
- Timon Gehr (10/12) Aug 09 2014 My guess is it is just a missing diagnostic for the missing support for
- H. S. Teoh via Digitalmars-d (7/25) Aug 09 2014 Aha! I think you're right. Moving declaration into main() and changing
Here's a lovely Saturday morning exercise for you D aficionados out there: struct S(alias fun) { auto g() { return fun(0); } } auto f(int arr) { return S!(a => arr)(); } auto r = f(2); void main() { r.g(); } This causes a segfault at runtime. Moving the declaration of r inside main() fixes the problem. Why? https://issues.dlang.org/show_bug.cgi?id=11826 My suspicion is that the lambda is trying to access the local variable 'arr', which has gone out of scope. T -- Leather is waterproof. Ever see a cow with an umbrella?
Aug 09 2014
On 08/09/2014 07:11 PM, H. S. Teoh via Digitalmars-d wrote:This causes a segfault at runtime. Moving the declaration of r inside main() fixes the problem. Why?My guess is it is just a missing diagnostic for the missing support for closures in CTFE. You are effectively trying to do something like auto foo(int a){ return (int x)=>x+a; } auto d=foo(2); which fails with Error: closures are not yet supported in CTFE
Aug 09 2014
On Sat, Aug 09, 2014 at 07:39:51PM +0200, Timon Gehr via Digitalmars-d wrote:On 08/09/2014 07:11 PM, H. S. Teoh via Digitalmars-d wrote:Aha! I think you're right. Moving declaration into main() and changing it to enum (to force CTFE) causes the same problem. So, looks like it's a missing check for an unsupported feature in CTFE. T -- Shin: (n.) A device for finding furniture in the dark.This causes a segfault at runtime. Moving the declaration of r inside main() fixes the problem. Why?My guess is it is just a missing diagnostic for the missing support for closures in CTFE. You are effectively trying to do something like auto foo(int a){ return (int x)=>x+a; } auto d=foo(2); which fails with Error: closures are not yet supported in CTFE
Aug 09 2014