Comment #0 by moonlightsentinel — 2020-06-08T10:49:08Z
-preview=nosharedaccess raises an error for aggregates that are not zero-initialized.
=============================================
struct S
{
int i = 2;
}
interface I
{
void foo();
}
class C : I
{
int i;
override void foo() {}
}
union U
{
int i = 1;
bool b;
}
void main()
{
shared int num;
shared S s;
shared I i;
shared C c;
shared U u;
}
=============================================
shared_init.d(1): Error: direct access to shared S is not allowed, see core.atomic
shared_init.d(17): Error: direct access to shared U is not allowed, see core.atomic
Comment #1 by dlang-bot — 2020-09-13T19:45:08Z
@Geod24 created dlang/dmd pull request #11726 "Fix 20908 - Improve `shared` access detection" fixing this issue:
- Fix 20908 - Improve `shared` access detection
There were quite a few positives with the previous approach.
Essentially, we cannot perform it during expression semantic,
within things like `visit(PtrExp)` methods, because we need
to be aware of our context.
Instead of adding yet another flag to `Scope` (which would need
to be flipped on and off), we use a visitor called from a higher
level (namely, the unary / binary expression semantic).
This should also make it easier to extend in the future,
for example by adding support for bypassing the check if
the constructor is `pure`.
https://github.com/dlang/dmd/pull/11726
Comment #2 by nick — 2023-03-16T16:15:25Z
Still happens with v2.102.2. I don't think the pull really got merged.
Comment #3 by dlang-bot — 2023-03-22T10:35:24Z
@RazvanN7 created dlang/dmd pull request #15023 "Fix Issue 20908 - -preview=nosharedaccess requires zero-initializion for aggregates" fixing this issue:
- Fix Issue 20908 - -preview=nosharedaccess requires zero-initializion for aggregates
https://github.com/dlang/dmd/pull/15023
Comment #4 by dlang-bot — 2023-03-22T15:37:22Z
dlang/dmd pull request #15023 "Fix Issue 20908 - -preview=nosharedaccess requires zero-initializion for aggregates" was merged into stable:
- 06fe8c4c09c97e7c666418cd568e30eb6f5b195d by RazvanN7:
Fix Issue 20908 - -preview=nosharedaccess requires zero-initializion for aggregates
https://github.com/dlang/dmd/pull/15023
Comment #5 by dlang-bot — 2023-04-01T22:15:10Z
dlang/dmd pull request #15066 "merge stable" was merged into master:
- ec071370017911d5984675c03c28e9b7603c3b14 by Razvan Nitu:
Fix Issue 20908 - -preview=nosharedaccess requires zero-initializion for aggregates (#15023)
https://github.com/dlang/dmd/pull/15066