https://issues.dlang.org/show_bug.cgi?id=14720
--- Comment #2 from Yuxuan Shui <yshu...@gmail.com> --- Seems this bug is not related to nested templates at all, it's more likely an 'auto ref' bug: import std.traits, std.range; void a(S)(auto ref S i) { } void b(S)(auto ref S i) if (isInputRange!S) { } void c(S)(ref S i) if (isInputRange!S) { } void devil(alias S)() { } void main() { a!string(""); //Works <--- This line affects the result of devil!(a!string) b!string(""); //Works //Next line is weird, it: //1. Err, 'auto ref can only be used with template function', if 'a' is not // instantiated with 'a!string' first //2. Works, if 'a!string' is done first alias x = devil!(a!string); alias xx = devil!(b!string); //Err, template doesn't match alias xxx = devil!(c!string); //Works } --