[Issue 4215] Intrduce auto ref parameters for class template variables
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Mar 17 13:59:17 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=4215
RazvanN <razvan.nitu1305 at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |razvan.nitu1305 at gmail.com
Resolution|--- |WONTFIX
--- Comment #5 from RazvanN <razvan.nitu1305 at gmail.com> ---
This code compiles:
void bar(T)(auto ref T item)
{
}
void main()
{
int i;
bar!(int)(i);
}
This code also compiles:
template bar(T)
{
void bar(auto ref T item)
{
}
}
void main()
{
int a;
bar(2);
bar(a);
}
This, however, does not compile:
class Foo(T)
{
void bar(auto ref T item)
{
}
}
void main()
{
Foo!(int) f;
}
And it cannot compile since once you instantiate Foo the compiler needs to know
how to instantiate bar. Since bar is not a templated function the compiler
cannot resolve `auto ref` and therefor correctly outputs the error that `auto
ref` parameters are allowed only for templated functions. The easy fix is to
template bar.
This enhancement request is invalid.
--
More information about the Digitalmars-d-bugs
mailing list