[Issue 14720] Template function reported as non-template

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jun 22 17:30:30 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14720

--- Comment #3 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Yuxuan Shui from comment #2)
> Seems this bug is not related to nested templates at all, it's more likely
> an 'auto ref' bug:

`auto ref` parameter is allowed for template functions, AND needs actual
function argument to deduce its ref-ness. For example:

void foo(auto ref int x) {}    // non-template function
// -> NG, auto can only be used for template function parameters

void bar(T)(auto ref T x) {}
void main() {
    int n;

    // IFTI (implicit function template instantiation)
    bar(1);      // OK, parameter x is deduced to non-ref
    bar(n);      // OK, parameter x is deduced to ref

    // partial template specialization + IFTI
    bar!int(1);  // also OK, equivalent with bar(1)
    bar!int(n);  // also OK, equivalent with bar(n)

    // explicit instantiation without IFTI
    alias b = bar!int;
    // NG! auto ref parameter x cannot deduce its ref-ness, therefore
    // sole auto ref parameter is rejected as same as foo definition.
}

--


More information about the Digitalmars-d-bugs mailing list