[Issue 8204] Can't instantiate auto ref template explicitly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 17 06:30:27 UTC 2020


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

Simen Kjaeraas <simen.kjaras at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Alias causes error: "auto   |Can't instantiate auto ref
                   |can only be used for        |template explicitly
                   |template function           |
                   |parameters"                 |

--- Comment #6 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
We could argue that foo!int should alias to the non-ref version, and foo!(ref
int) (or, in valid D, foo!(Parameters!((ref int){}))) give the ref version. So
far, so good.

However, auto ref functions are a strange breed, and this is perfectly valid:

    void fun()(auto ref int){}

In this case there's no template argument to carry the information about
refness, so no explicit instantiation can be made. In some cases we can add
extra parameters and simply extract the refness from those, so the definition
as seen by the compiler is more like this:

    void fun(__Hidden)(transferRefness!(__Hidden, int)) {}

This, however, breaks for variadic templates, so is also not a real solution.
All in all, there's no provision in the language today for explicitly
instantiating auto ref functions, and no obvious point to extend to give this
ability. A solution to this issue will likely require a DIP.

--


More information about the Digitalmars-d-bugs mailing list