Bug 12795 – atomicLoad allows unsafe removal of shared from class references

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2014-05-24T13:43:58Z
Last change time
2019-08-18T22:25:05Z
Assigned to
No Owner
Creator
kirsybuu

Comments

Comment #0 by kirsybuu — 2014-05-24T13:43:58Z
Tested with dmd v2.066-devel-ca213d2 --- struct Struct { int x; } class Class { int x; } void main() { import core.atomic; shared(Struct*) si = new shared Struct; shared(Struct)* i = atomicLoad(si); // Safe as expected shared(Class) sd = new shared(Class)(); Class d = atomicLoad(sd); // Unsafe! } --- To find out what went wrong, I copied the definition of atomicLoad and modified it as such: --- template HeadUnshared(T) { static if( is( T U : shared(U*) ) ) alias shared(U)* HeadUnshared; else alias T HeadUnshared; } HeadUnshared!(T) atomicLoad(T)( ref const shared T val ) nothrow { pragma(msg, "typeof(val) == " ~ typeof(val).stringof); pragma(msg, "T == " ~ T.stringof); pragma(msg, "typeof(return) == " ~ typeof(return).stringof); return typeof(return).init; } --- And the output is: typeof(val) == shared(const(Struct*)) T == shared(Struct)* typeof(return) == shared(Struct)* typeof(val) == shared(const(Class)) T == Class typeof(return) == Class
Comment #1 by ag0aep6g — 2019-08-18T22:25:05Z
*** This issue has been marked as a duplicate of issue 16230 ***