Erroneous "auto can only be used for template function parameters"?

Yuxuan Shui via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 19 18:50:09 PDT 2015


Try to compile this code snippet:

import std.traits;
template a(R) {
	auto a(S)(auto ref R i) {
		return cast(S)i*2;
	}
}
template ReturnTypeEx(alias A, B) {
	alias ReturnTypeEx = ReturnType!(A!B);
}
template b(alias R) {
	int b(S)(S i) {
		alias Ra = ReturnTypeEx!(R, S);
		return cast(int)R!S(i);
	}
}
void main() {
	alias bb = b!(a!ulong);
	pragma(msg, ReturnTypeEx!(bb, int));
}

DMD reports:
sadf.d(3): Error: auto can only be used for template function 
parameters
sadf.d(8): Error: template instance sadf.a!ulong.A!int error 
instantiating
sadf.d(12):        instantiated from here: ReturnTypeEx!(a, int)
sadf.d(8):        instantiated from here: A!int
sadf.d(18):        instantiated from here: ReturnTypeEx!(b, int)
sadf.d(18):        while evaluating pragma(msg, ReturnTypeEx!(b, 
int))

But a(S)(auto ref R) is indeed a template function, so I don't 
understand.


More information about the Digitalmars-d-learn mailing list