www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9203] New: Template functions with auto ref params do not share static locals

http://d.puremagic.com/issues/show_bug.cgi?id=9203

           Summary: Template functions with auto ref params do not share
                    static locals
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: peter.alexander.au gmail.com



17:10:49 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 24 2012