Problems with std.traits.isSafe & SafeD
Jonathan M Davis
jmdavisProg at gmx.com
Sun Dec 12 11:00:38 PST 2010
On Sunday 12 December 2010 05:55:11 Johannes Pfau wrote:
> Hmm, next problem with safe D.
>
> unittest
> {
> @safe int tf(int i){return i;}
> bool a = isSafe!(tf);
> assert(a == true);
> static assert(isSafe!(tf));
> static assert(isSafe!(typeof(&tf)));
> }
>
> All three asserts fail! Even the example from std.traits doesn't work for
> me, isSafe always returns false. And the last assert causes another
> problem:
> ---------------------------------------------------------------------------
> --- event.d(170): Error: template instance isSafe!(int delegate(int i))
> does not match template declaration isSafe(alias func)
> ---------------------------------------------------------------------------
> ---
>
> So it's not possible to check the safety of a delegate Type? It seems like
> isSafe just doesn't support this use case, maybe it could be added, but
> why is "typeof(&tf)" "int delegate(int i)"? Shouldn't @safe be somewhere
> in that type?
There are a number of bugs relating to delegates. Among those, it appears that
_traits (and probably std.traits) doesn't handle them properly. e.g. this bug
here:
http://d.puremagic.com/issues/show_bug.cgi?id=4816
Open a bug report on it, if you haven't already. delegates and function pointers
already don't deal with modifiers like const correctly. It doesn't surprise me in
the least that they don't handle @safe correctly.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list