digitalmars.D.learn - Problems with std.traits.isSafe & SafeD
- Johannes Pfau (22/22) Dec 12 2010 Hmm, next problem with safe D.
- Jonathan M Davis (9/33) Dec 12 2010 There are a number of bugs relating to delegates. Among those, it appear...
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? -- Johannes Pfau
Dec 12 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
Dec 12 2010