D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1758 - Lazy Parameters in Closures - Access Violation
Summary: Lazy Parameters in Closures - Access Violation
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P3 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2008-01-01 10:42 UTC by Xinok
Modified: 2015-06-09 01:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Xinok 2008-01-01 10:42:06 UTC
The following code will cause an access violation error.

T delegate() lazier(T)(lazy T arg){
	bool once = true;
	T value;
	return {
		if(once){
			once = false;
			value = arg;
		}
		return value;
	};
}

void main(){
	auto l = lazier(rand());
	writeln(l()); // Access violation
}
Comment 1 Don 2010-10-19 08:33:22 UTC
This failed in 2.012, but was fixed by 2.020.