[Issue 20941] New: __traits(getMember) should not allow safe code to access private fields
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jun 17 12:38:03 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20941
Issue ID: 20941
Summary: __traits(getMember) should not allow safe code to
access private fields
Product: D
Version: D2
Hardware: x86
OS: Mac OS X
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: andrei at erdani.com
This is taken from DIP 1035:
struct S {
private union {
int x;
int* y;
}
private int tag; // x if 0, y if 1
// public @trusted interface follows
void set(int rhs) @trusted {
if (tag == 0) x = rhs;
else *y = rhs;
}
....
}
Allowing safe code to modify tag from @safe code, followed by calling set(),
results in unsafe code from safe functions.
This could be relaxed to restrict access only for types that have @trusted
functions.
--
More information about the Digitalmars-d-bugs
mailing list