D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5949 - Mutable enum matrix rows
Summary: Mutable enum matrix rows
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2011-05-07 16:08 UTC by bearophile_hugs
Modified: 2020-09-06 22:17 UTC (History)
2 users (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-05-07 16:08:46 UTC
This D2 code compiles and runs with no errors (DMD 2.053beta), but it's wrong:


void main() {
    enum int[][] data = [[1]];
    foreach (a; data)
        a[0]++;
    assert(data[0][0] == 1);
    foreach (ref a; data)
        a[0]++;
    assert(data[0][0] == 1);
}
Comment 1 Infiltrator 2014-03-19 18:02:42 UTC
Issue still exists as of v2.065.
Comment 2 Mathias LANG 2020-09-06 22:17:59 UTC
The `enum` gives a literal, so the compiler is correct here.
The code works as expected. Using `[static] immutable` will give the desired error.