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:52:48 PDT 2015


On Saturday, 20 June 2015 at 01:50:11 UTC, Yuxuan Shui wrote:
> 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.

Another thing I discovered is instantiation like this: (a!T)!S 
will result in "C style cast illegal", which is clearly wrong 
because this is not a cast, (a!T) is not necessarily a type.


More information about the Digitalmars-d-learn mailing list