[Issue 17284] opDispatch allows bypassing @safe on unions

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Mar 29 12:41:30 PDT 2017


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

ZombineDev <petar.p.kirov at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |petar.p.kirov at gmail.com
          Component|phobos                      |dmd
           Hardware|x86_64                      |All
            Summary|std.experimental.typecons.F |opDispatch allows bypassing
                   |inal allows bypassing @safe |@safe on unions
                   |on unions                   |
                 OS|Linux                       |All
           Severity|normal                      |major

--- Comment #1 from ZombineDev <petar.p.kirov at gmail.com> ---
The issue has little to do with std.experimental.typecons.Final. Final just
uses std.typecons.Proxy. I added an assert(0) on line 5585 in std.typecons from
dmd 2.073.2 and got this:
$ ./main
core.exception.AssertError@/home/zlx/dlang/dmd-2.073.2/linux/bin64/../../src/phobos/std/typecons.d(5585):
Assertion failure
----------------
??:? _d_assert [0x4296e4]
??:? pure nothrow ref @property @nogc return @safe int
std.experimental.typecons.Final!(main.U).Final.__mixin8.opDispatch!("i").opDispatch!(std.experimental.typecons.Final!(main.U).Final).opDispatch()
[0x428684]
??:? _Dmain [0x42845b]
??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x429c9f]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate()) [0x429bc7]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).runAll() [0x429c44]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate()) [0x429bc7]
??:? _d_run_main [0x429b33]
??:? main [0x42871f]
??:? __libc_start_main [0x4b801f44]
(dmd-2.073.2)/mnt/d/tmp_code/final_safe

This issue can easily be reproduced with the following code:
class C { }
union U {
    C c;
    int i;
}

struct S(T)
{
    private T value__;

    @property auto ref opDispatch(string name)()
    {
        return mixin("value__." ~ name);
    }
}

void main() @safe {
    S!U u;
    u.c = new C; // compiles (!!!)
    u.i++;       // uh-oh
}

Therefore I'm changing the component to dmd.

--


More information about the Digitalmars-d-bugs mailing list