Bug 16230 – core.atomic.atomicLoad removes shared from aggregate types too eagerly
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-07-03T12:32:47Z
Last change time
2019-08-18T22:25:05Z
Keywords
pull
Assigned to
ag0aep6g
Creator
ag0aep6g
Comments
Comment #0 by ag0aep6g — 2016-07-03T12:32:47Z
import core.atomic;
struct S { int* p; }
class C { int i; }
shared int i = 0;
shared int* p = &i;
shared int[] a = [0];
shared S s = shared S(&i);
shared C c = new C;
void main()
{
auto j = atomicLoad(i);
pragma(msg, typeof(j)); /* "int" - Ok, it's a copy. */
auto q = atomicLoad(p);
pragma(msg, typeof(q)); /* "shared(int)*" - Good. */
auto b = atomicLoad(a);
pragma(msg, typeof(b)); /* "shared(int)[]" - Good. */
auto t = atomicLoad(s);
pragma(msg, typeof(t)); /* "S" - Bad. */
auto d = atomicLoad(c);
pragma(msg, typeof(d)); /* "C" - Bad. */
/* t and d refer to shared data, but their types are completely
un-shared. The point of shared has been defeated.
For example, I can now accidentally use ++ on the ints: */
++*t.p; /* No deprecation. Bad. */
++d.i; /* Ditto. */
/* With q and b I get a deprecation message, because they're
properly typed: */
++*q; /* "Deprecation: read-modify-write operations are not allowed
for shared variables. Use core.atomic.atomicOp!"+="(*q, 1)
instead." Good. */
++b[0]; /* Ditto. */
}