[Issue 17284] Template function attribute inference wrongly infers @safe for accessing overlapping pointer fields in unions

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Mar 29 13:17:06 PDT 2017


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

--- Comment #5 from hsteoh at quickfur.ath.cx ---
Oh my, it gets worse: ref has nothing to do with it at all!  Look at this
blatant violation of @safe:

------
class C { }
union U { C c; int i; }

void func(T)(T t)
{       
        t.c = new C;
        t.i++;       // !!!
}

pragma(msg, typeof(func!U));
------

Compiler output:
------
pure nothrow @safe void(U t)
------

Looks like attribute inference is a free license to violate @safety. :-D  Or,
more precisely, attribute inference completely forgets to check for overlapping
pointers.

--


More information about the Digitalmars-d-bugs mailing list