Bug 6759 – missing initialization in foreach with alias this

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-10-02T05:03:00Z
Last change time
2011-10-05T12:04:09Z
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2011-10-02T05:03:02Z
struct Range { size_t front() { return 0; } void popFront() { empty = true; } bool empty; } struct ARange { Range range; alias range this; } void main() { ARange arange; assert(arange.front == 0); foreach(e; arange) {} } --- Foreach creates a reference to arange. The expression that initializes the reference is dropped for alias this aggregates. This is a regression introduced by https://github.com/D-Programming-Language/dmd/commit/6a2aefdb468d20aa8d498c8930c2613d78a91238 as a fix to #2781.
Comment #1 by k.hara.pg — 2011-10-02T12:37:22Z
Your patch was already merged (commit: f53ff46), and it looks correct to me the fixing lack of merging prelude before semantic. But, your sample code works before merging (commit: 07f719e), so that code is not test case of this issue. Do you have right test case?
Comment #2 by bugzilla — 2011-10-02T12:54:32Z
Comment #3 by code — 2011-10-05T12:04:09Z
(In reply to comment #1) > Your patch was already merged (commit: f53ff46), and it looks correct to me the > fixing lack of merging prelude before semantic. > > But, your sample code works before merging (commit: 07f719e), so that code is > not test case of this issue. > > Do you have right test case? This is probably due to constant folding or optimization. The merged version has 'assert(e == 0);' in the loop body.