As expected, accessing a union that contains pointers is not @safe:
----
union U
{
string s;
int x;
}
U u;
void f() @safe { auto s = u.s; } /* Error: field U.s cannot access pointers in @safe code that overlap other fields */
----
But attribute inference accepts it as @safe:
----
union U
{
string s;
int x;
}
U u;
auto f1() { auto s = u.s; } /* Should be inferred as @system. */
void f2()() { auto s = u.s; } /* ditto */
void g() @safe
{
void f3() { auto s = u.s; } /* ditto */
f1(); /* Should be rejected with error "cannot call @system function". */
f2(); /* ditto */
f3(); /* ditto */
}
----
Comment #1 by dlang-bot — 2020-03-09T23:28:00Z
@aG0aep6G created dlang/dmd pull request #10884 "fix issue 20655 - attribute inference accepts unsafe union access as …" fixing this issue:
- fix issue 20655 - attribute inference accepts unsafe union access as @safe
https://github.com/dlang/dmd/pull/10884
Comment #2 by dlang-bot — 2020-03-10T00:52:25Z
@aG0aep6G created dlang/druntime pull request #2982 "remove wrong @safe attributes" mentioning this issue:
- remove wrong @safe attributes
When issue 20655 ("attribute inference accepts unsafe union access as
@safe") is fixed, DMD correctly complains about these.
https://github.com/dlang/druntime/pull/2982
Comment #3 by dlang-bot — 2020-03-10T00:54:11Z
@aG0aep6G created dlang/phobos pull request #7418 "mark access to `value.store.str` as @trusted" mentioning this issue:
- mark access to `value.store.str` as @trusted
When issue 20655 ("attribute inference accepts unsafe union access as
@safe") is fixed, DMD correctly complains about the operation being unsafe.
https://github.com/dlang/phobos/pull/7418
Comment #4 by dlang-bot — 2020-03-10T02:28:43Z
dlang/phobos pull request #7418 "mark access to `value.store.str` as @trusted" was merged into master:
- 0bd2fa43346cbc62a202669cf87d4267b1b4aae7 by aG0aep6G:
mark access to `value.store.str` as @trusted
When issue 20655 ("attribute inference accepts unsafe union access as
@safe") is fixed, DMD correctly complains about the operation being unsafe.
https://github.com/dlang/phobos/pull/7418
Comment #5 by dlang-bot — 2020-03-10T03:17:12Z
dlang/druntime pull request #2982 "remove wrong @safe attributes" was merged into master:
- eb53170ea40fdc90b1dec38050e8100d8f944394 by aG0aep6G:
remove wrong @safe attributes
When issue 20655 ("attribute inference accepts unsafe union access as
@safe") is fixed, DMD correctly complains about these.
https://github.com/dlang/druntime/pull/2982
Comment #6 by dlang-bot — 2020-04-27T14:00:01Z
@ibuclaw updated dlang/druntime pull request #2871 "core.math: Re-enable disabled tests and update toPrec comment" mentioning this issue:
- remove wrong @safe attributes
When issue 20655 ("attribute inference accepts unsafe union access as
@safe") is fixed, DMD correctly complains about these.
https://github.com/dlang/druntime/pull/2871
Comment #7 by schveiguy — 2020-10-03T03:58:00Z
This is a regression since 2.072.
Upping importance, this regression is 4 years old!
Comment #8 by dlang-bot — 2023-01-16T13:17:41Z
@dkorpel created dlang/dmd pull request #14827 "fix issue 20655 - attribute inference accepts unsafe union access as @safe" fixing this issue:
- fix issue 20655 - attribute inference accepts unsafe union access as @safe
https://github.com/dlang/dmd/pull/14827
Comment #9 by dlang-bot — 2023-08-03T13:50:41Z
dlang/dmd pull request #14827 "fix issue 20655 - attribute inference accepts unsafe union access as @safe" was merged into master:
- f55247d8c7fc3d7cf26dbbe34f03708515a5272b by Dennis Korpel:
Fix 20655 - attribute inference accepts unsafe union access as `@safe`
https://github.com/dlang/dmd/pull/14827