December 01, 2013 Template condition triggers compiler error? | ||||
|---|---|---|---|---|
| ||||
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?
| ||||
December 02, 2013 Re: Template condition triggers compiler error? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Namespace | 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 | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply