Bug 14657 – can alias auto ref function but only after it's been called before
Status
RESOLVED
Resolution
DUPLICATE
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-06-05T20:03:00Z
Last change time
2016-11-20T22:57:11Z
Assigned to
nobody
Creator
ag0aep6g
Comments
Comment #0 by ag0aep6g — 2015-06-05T20:03:27Z
Related to issue 14656 (printing bad "auto") and issue 9204 (can't alias auto ref function).
This errors out:
----
void unaryFun()(auto ref int a) pure nothrow @safe @nogc {}
void main()
{
alias u = unaryFun!();
}
----
test.d(1): Error: auto can only be used for template function parameters
test.d(4): Error: template instance test.unaryFun!() error instantiating
But these compile and print different types:
----
void unaryFun()(auto ref int a) pure nothrow @safe @nogc {}
void main()
{
unaryFun!()(41);
alias u = unaryFun!();
pragma(msg, typeof(u)); /* ...(auto int a) */
}
----
----
void unaryFun()(auto ref int a) pure nothrow @safe @nogc {}
void main()
{
int x;
unaryFun!()(x);
alias u = unaryFun!();
pragma(msg, typeof(u)); /* ...(auto ref int a) */
}
----
I think they should either all error or all print "auto ref int".
Comment #1 by kozzi11 — 2015-06-09T06:18:19Z
IMHO this should not work:
alias u = unaryFun!();
it does not make sense. In curent dmd it alias to first template instantiation.
So even this does not work:
void unaryFun()(auto ref int a) pure nothrow @safe @nogc {}
void main()
{
int x;
unaryFun!()(x);
unaryFun!()(41);
alias u = unaryFun!();
u(41);
}
m.d(8): Error: function m.unaryFun!().unaryFun (auto ref int a) is not callable using argument types (int)
So I would say
alias u = unaryFun!(); should be forbidden and some better error message can be print.
Something like this:
Error: alias u = unaryFun!() cannot be use do you mean alias u = unaryFun?
Comment #2 by kozzi11 — 2015-06-09T06:43:09Z
Ok maybe I am wrong:
template unaryFun()
{
void unaryFun(ref int a) pure nothrow @safe @nogc {}
void unaryFun(int a) pure nothrow @safe @nogc {}
}
void unaryFun2()(auto ref int a) pure nothrow @safe @nogc {}
void main()
{
int x;
alias unaryFun!() u;
alias unaryFun2!() u2;
u(41);
u2(41);
}
this works ok for u, but not for u2.
Comment #3 by b2.temp — 2016-11-20T22:57:11Z
*** This issue has been marked as a duplicate of issue 9204 ***