Bug 24709 – Cannot get a reference to each element of an array on foreach-loop with -preview=nosharedaccess

Status
NEW
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-08-17T15:39:00Z
Last change time
2024-12-13T19:36:51Z
Assigned to
No Owner
Creator
Kazuki Komatsu
Moved to GitHub: dmd#20496 →

Comments

Comment #0 by komatsu.kazuki.op — 2024-08-17T15:39:00Z
References to shared variables can be obtained without atomic operations, but foreach statements that take references to array elements produce unexpected errors with -preview=nosharedaccess. I have confirmed that all dmd compilers from version 2.093.1 to latest (and also in the current nightly where the last commit hash is 1d2e15e) have the same bug. ```d void main() { //OK: We can get a reference of a shared variable. { void foo(ref shared(int) a) {} shared int a; foo(a); } //NG: Cannot get a reference to each element of an array on foreach-loop { shared(int)[] arr; // Error: direct access to shared `__r2[__key3]` is not allowed, see `core.atomic` foreach(ref e; arr) {} } } ```
Comment #1 by robert.schadek — 2024-12-13T19:36:51Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20496 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB