Struct with lambda argument causes segfault at runtime

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Sat Aug 9 10:11:55 PDT 2014


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?


More information about the Digitalmars-d mailing list