August 17 [Issue 24709] New: Cannot get a reference to each element of an array on foreach-loop with -preview=nosharedaccess | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24709 Issue ID: 24709 Summary: Cannot get a reference to each element of an array on foreach-loop with -preview=nosharedaccess Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody@puremagic.com Reporter: komatsu.kazuki.op@tut.jp 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) {} } } ``` -- |
Copyright © 1999-2021 by the D Language Foundation