Template condition triggers compiler error?

Namespace rswhite4 at googlemail.com
Sun Dec 1 08:07:16 PST 2013


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?


More information about the Digitalmars-d-learn mailing list