D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6522 - [CTFE] Problem with opAssign call in foreach(ref)
Summary: [CTFE] Problem with opAssign call in foreach(ref)
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-08-17 11:14 UTC by bearophile_hugs
Modified: 2011-11-16 11:54 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 bearophile_hugs 2011-08-17 11:14:58 UTC
Reduced code (Foo originally was BigInt):


struct Foo {
    bool b = false;
    void opAssign(int x) {
        this.b = true;
    }
}
int foo() {
    Foo[1] array;
    foreach (ref item; array)
        item = 1;
    return 0;
}
enum r = foo(); // error
void main() {
//    const r = foo(); // OK
}


DMD 2.055beta gives:

test.d(9): Error: variable __key4 is used before initialization
test.d(10): Error: cannot evaluate item.opAssign(1) at compile time
test.d(13): Error: cannot evaluate foo() at compile time