Comment #0 by peter.alexander.au — 2012-12-24T17:10:49Z
void foo()(auto ref int x)
{
import std.stdio;
static int calls = 0;
writeln(calls++);
}
void main()
{
int x = 0;
foo(x);
foo(x + x);
}
The output is:
0
0
I would have expected:
0
1
The spec says about auto ref parameters: "An auto ref function template parameter becomes a ref parameter if its corresponding argument is an lvalue, otherwise it becomes a value parameter"
I understand that auto ref is implemented as creating two different functions for each arg l/rvalue type, but it isn't clear in the spec whether those are actually different functions (with different adresses/sets of static vars) or just conceptually different (like with inout params).
If they are intended to be completely different functions then I think this needs to be made very clear in the spec.
Comment #1 by dlang-bugzilla — 2014-03-20T09:22:29Z
Yes, I'm quite sure this works as intended.
Comment #2 by robert.schadek — 2024-12-15T15:22:00Z