Bug in Auto Functions and Template? Or Am I Just Crazy...

Michael pongad at gmail.com
Wed Jun 27 02:07:56 PDT 2012


Hello all,
   I came across some weird behaviors yesterday and I can't figure 
out what it's about.

(1)
auto factorial(int n) {
	if (n < 2) return 1;
	return n * factorial(n-1);
}

The compiler complained about "forward declaration of factorial". 
If I change the return type to int, the problem goes away. I can 
understand that with the recursion, it might be impossible for 
the compiler to deduce the type of factorial and so it compile 
errors, but I don't see anything about that on the Language 
Reference. Is this the intended behavior?

(2)
auto stuff(T)(T[] arr) {
	auto inner(T[] s) {
		s[0] = 0;
	}
	arr.inner();
}
This time the compiler complained about 'inner' not being 
defined. This time I have no idea what is wrong.

Thanks for your help!
Michael


More information about the Digitalmars-d-learn mailing list