5976 – "variable used before set" with foreach with ref + scope(failure) + structure method + -O -inline

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5976 - "variable used before set" with foreach with ref + scope(failure) + structure method + -O -inline
Summary: "variable used before set" with foreach with ref + scope(failure) + structure...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
Reported: 2011年05月10日 15:38 UTC by Vladimir Panteleev
Modified: 2011年05月12日 20:19 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2011年05月10日 15:38:19 UTC
When compiled with -O: test.d(9): Error: variable b used before set
struct B { void bar(){} }
B[] barr;
void foo()
{
	foreach (ref b; barr)
	{
		scope(failure)
			b.bar();
		assert(&b); // do anything with b
	}
}
Comment 1 Don 2011年05月11日 08:17:20 UTC
This only happens with -O -inline (-O alone is not sufficient).
Comment 2 Don 2011年05月11日 08:28:11 UTC
Reduced test case that doesn't require structs or -inline.
Compile with -O.
void bug5976()
{
 int[] barr;
 int * k;
 foreach (ref b; barr)
 {
 scope(failure)
 k = &b;
 k = &b;
 }
}


AltStyle によって変換されたページ (->オリジナル) /