www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17284] New: std.experimental.typecons.Final allows bypassing


          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 puremagic.com
          Reporter: hsteoh quickfur.ath.cx

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.)

Mar 29 2017