[Issue 12795] New: atomicLoad allows unsafe removal of shared from class references
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sat May 24 06:43:58 PDT 2014
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 at puremagic.com
Reporter: kirsybuu at 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
--
More information about the Digitalmars-d-bugs
mailing list