Bug 24232 – ref for index of foreach for arrays is not allowed by spec but accepted by compiler.

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2023-11-07T18:05:16Z
Last change time
2024-12-13T19:31:37Z
Keywords
pull
Assigned to
No Owner
Creator
james.gray
Moved to GitHub: dmd#20353 →

Comments

Comment #0 by james.gray — 2023-11-07T18:05:16Z
According to https://dlang.org/spec/statement.html#foreach_over_arrays point 2, "ref" on "index" is not allowed. However, the following compiles: import std; void main() { foreach(ref i, x; [1,2,3,4,5]) { writeln(x); i++; } } and produces: 1 3 5
Comment #1 by dlang-bot — 2024-04-14T17:36:24Z
@ntrel updated dlang/dmd pull request #16381 "[foreach] Deprecate `ref` for array index or range parameter" fixing this issue: - Fix Bugzilla 24232 - ref for index of foreach for arrays is not allowed by spec but accepted by compiler https://github.com/dlang/dmd/pull/16381
Comment #2 by robert.schadek — 2024-12-13T19:31:37Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20353 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB