[Issue 9203] New: Template functions with auto ref params do not share static locals

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Dec 24 17:10:54 PST 2012


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 at puremagic.com
        ReportedBy: peter.alexander.au at gmail.com


--- Comment #0 from Peter Alexander <peter.alexander.au at gmail.com> 2012-12-24 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: -------


More information about the Digitalmars-d-bugs mailing list