[Issue 8204] Alias causes error: "auto can only be used for template function parameters"

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jul 18 05:34:27 PDT 2017


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

--- Comment #2 from Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> ---
(In reply to dlang+issues from comment #0)
> void foo(T)(ref auto T v) { }
> alias foo!int bar; // Error: auto can only be used for template function
> parameters

What is the expected type of "bar" here? The compiler can't know whether the
instantiated function should take its parameter by ref or not, so I'm not sure
whether this issue is valid. What is the expected behaviour?

As a workaround, you can move the type to a separate outer template using the
eponymous template pattern:

template foo(T)
{
    void foo()(auto ref T v) { }
}
alias foo!int bar;

Unfortunately, this breaks calling foo (as in `foo(5)`). The type will need to
be indicated explicitly (e.g. `foo!int(5)`).

--


More information about the Digitalmars-d-bugs mailing list