Bug 4215 – Intrduce auto ref parameters for class template variables

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-05-20T15:35:34Z
Last change time
2021-03-17T13:59:17Z
Assigned to
No Owner
Creator
Trass3r

Comments

Comment #0 by hoganmeier — 2010-05-20T15:35:34Z
Something like class Foo(T) { void bar(auto ref T item) { } } doesn't work.
Comment #1 by bugzilla — 2010-05-20T22:20:48Z
Exactly what does it do that is wrong?
Comment #2 by hoganmeier — 2010-05-21T05:12:20Z
class Foo(T) { void bar(auto ref T item) { } } void main() { Foo!(int) f; } gives test.d(3): Error: auto can only be used for template function parameters Hmm ok, maybe it rather is an enhancement.
Comment #3 by hoganmeier — 2010-05-21T05:28:54Z
the more general code: template bar(T) { void bar(auto ref T item) { } } void main() { bar!(int) f; } also doesn't work. Even the following doesn't compile: void bar(T)(auto ref T item) { } void main() { int i; bar!(int)(i); // while bar(i); is OK } test.d(1): Error: auto can only be used for template function parameters test.d(8): Error: template instance test.bar!(int) error instantiating
Comment #4 by bugzilla — 2010-05-21T09:49:12Z
What semantics do you wish auto to have for parameters? i.e. why are you using it?
Comment #5 by razvan.nitu1305 — 2021-03-17T13:59:17Z
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.