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

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-05-10T15:38:00Z
Last change time
2011-05-12T20:19:53Z
Keywords
rejects-valid
Assigned to
nobody
Creator
dlang-bugzilla

Comments

Comment #0 by dlang-bugzilla — 2011-05-10T15:38:19Z
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 by clugdbug — 2011-05-11T08:17:20Z
This only happens with -O -inline (-O alone is not sufficient).
Comment #2 by clugdbug — 2011-05-11T08:28:11Z
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; } }
Comment #3 by bugzilla — 2011-05-12T17:27:15Z
Comment #4 by dlang-bugzilla — 2011-05-12T20:19:53Z