D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14657 - can alias auto ref function but only after it's been called before
Summary: can alias auto ref function but only after it's been called before
Status: RESOLVED DUPLICATE of issue 9204
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 minor
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-05 20:03 UTC by ag0aep6g
Modified: 2016-11-20 22:57 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ag0aep6g 2015-06-05 20:03:27 UTC
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 Daniel Kozak 2015-06-09 06:18:19 UTC
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 Daniel Kozak 2015-06-09 06:43:09 UTC
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 basile-z 2016-11-20 22:57:11 UTC

*** This issue has been marked as a duplicate of issue 9204 ***