digitalmars.D.learn - Template condition triggers compiler error?
- Namespace (56/56) Dec 01 2013 This code compiles:
- Kenji Hara (4/60) Dec 01 2013 Compiler bug.
This code compiles: ---- template gc_free(T) { static if (is(T : U*, U) || is(T : U[], U)) alias Type = T; else alias Type = T*; void gc_free(Type data) { import core.memory : GC; static if (is(Type : U[], U)) { GC.free(data.ptr); GC.minimize(); } else { GC.free(data); } data = null; } } ---- But with a template condition it triggers compiler errors: ---- template gc_free(T) if (!is(T == class)) { static if (is(T : U*, U) || is(T : U[], U)) alias Type = T; else alias Type = T*; void gc_free(Type data) { import core.memory : GC; static if (is(Type : U[], U)) { GC.free(data.ptr); GC.minimize(); } else { GC.free(data); } data = null; } } ---- Errors: share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(177): Error: template instance share.share!(A) error instantiating share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(197): Error: template instance share.share!(A) error instantiating share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type It seems to work on Linux with 64 bit, but it fails on Windows 7 32 bit. Bug, feature or my fault?
Dec 01 2013
On Sunday, 1 December 2013 at 16:07:18 UTC, Namespace wrote:This code compiles: ---- template gc_free(T) { static if (is(T : U*, U) || is(T : U[], U)) alias Type = T; else alias Type = T*; void gc_free(Type data) { import core.memory : GC; static if (is(Type : U[], U)) { GC.free(data.ptr); GC.minimize(); } else { GC.free(data); } data = null; } } ---- But with a template condition it triggers compiler errors: ---- template gc_free(T) if (!is(T == class)) { static if (is(T : U*, U) || is(T : U[], U)) alias Type = T; else alias Type = T*; void gc_free(Type data) { import core.memory : GC; static if (is(Type : U[], U)) { GC.free(data.ptr); GC.minimize(); } else { GC.free(data); } data = null; } } ---- Errors: share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(177): Error: template instance share.share!(A) error instantiating share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(197): Error: template instance share.share!(A) error instantiating share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type share.d(10): Error: undefined identifier Type It seems to work on Linux with 64 bit, but it fails on Windows 7 32 bit. Bug, feature or my fault?Compiler bug. https://d.puremagic.com/issues/show_bug.cgi?id=11662 Kenji Hara
Dec 01 2013