digitalmars.D.bugs - [Issue 12795] New: atomicLoad allows unsafe removal of shared from
- via Digitalmars-d-bugs (54/54) May 24 2014 https://issues.dlang.org/show_bug.cgi?id=12795
https://issues.dlang.org/show_bug.cgi?id=12795 Issue ID: 12795 Summary: atomicLoad allows unsafe removal of shared from class references Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: normal Priority: P1 Component: druntime Assignee: nobody puremagic.com Reporter: kirsybuu gmail.com 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 --
May 24 2014