Bug 3290 – accepts-invalid: non-const by-ref foreach over a const array is accepted

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-09-03T13:12:00Z
Last change time
2012-06-03T03:52:23Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
2korden

Comments

Comment #0 by 2korden — 2009-09-03T13:12:35Z
The following test-case shouldn't compile: void main() { const(int)[] array; foreach (ref int i; array) { // i = 42; } } Note that modifying the 'i' is still prohibited.
Comment #1 by bearophile_hugs — 2010-07-26T12:27:44Z
See also bug 4510
Comment #2 by k.hara.pg — 2012-06-01T09:57:28Z
Comment #3 by github-bugzilla — 2012-06-02T15:22:15Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/71fcb1b65f57ed842a7ff94d323420d7da9cfbc8 fix Issue 3290 - accepts-invalid: non-const by-ref foreach over a const array is accepted https://github.com/D-Programming-Language/dmd/commit/62d6363c59362025b0c809ee865dd52d78cbf33c Merge pull request #977 from 9rnsr/fix_foreach_arg Issue 3290,4510,5435 - Add strict type check for foreach argument
Comment #4 by bearophile_hugs — 2012-06-03T03:52:23Z
While testing this I have opened Issue 8189