[Issue 17284] New: std.experimental.typecons.Final allows bypassing @safe on unions

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Mar 29 10:47:40 PDT 2017


https://issues.dlang.org/show_bug.cgi?id=17284

          Issue ID: 17284
           Summary: std.experimental.typecons.Final allows bypassing @safe
                    on unions
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: hsteoh at quickfur.ath.cx

Code:
------
class C { }
union U {
    C c;
    int i;
}
void main() @safe {
    U u1;
    u1.c = new C; // compile error (correct, this is unsafe)
    u1.i++;       // (because you can do this)

    import std.experimental.typecons : Final;
    Final!U u2;
    u2.c = new C; // compiles (!!!)
    u2.i++;       // uh-oh
}
------

Expected behaviour: Final!U should not allow user code to bypass compiler's
@safety checks on assigning pointers to unions.

Or, at the minimum, Final should not be usable with unions. (It is
questionable, in fact, whether modifying members of a Final!U should even be
allowed in the first place.)

--


More information about the Digitalmars-d-bugs mailing list