www.digitalmars.com         C & C++   DMDScript  

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


           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

--- Comment #0 from Peter Alexander <peter.alexander.au gmail.com> 2012-12-24
17:10:49 PST ---
void foo()(auto ref int x)
    import std.stdio;
    static int calls = 0;

void main()
    int x = 0;
    foo(x + x);

The output is:

I would have expected:

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