[Issue 17284] ref returning function template allows bypassing @safe on unions

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


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

--- Comment #4 from hsteoh at quickfur.ath.cx ---
Interesting.  So it would appear that the problem is caused by attribute
inference wrongly inferring @safe for a template function that returns an
overlapping pointer field.

I.e.:

----
class C { }
union U { C c; int i; }
ref C func(T)(ref T t) { return t.c; }

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

Compiler output:
----
pure nothrow @nogc ref @safe C(return ref U t)
----

The correct inferred type should be:
----
pure nothrow @nogc ref @system C(return ref U t)
----

--


More information about the Digitalmars-d-bugs mailing list