Thread overview
[Issue 560] New: Cannot escape reference to variadic parameter
Nov 18, 2006
d-bugmail
Nov 18, 2006
d-bugmail
Dec 03, 2006
d-bugmail
November 18, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=560

           Summary: Cannot escape reference to variadic parameter
           Product: D
           Version: 0.174
          Platform: PC
               URL: http://www.digitalmars.com/d/function.html
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid, spec
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: deewiant@gmail.com
OtherBugsDependingO 511
             nThis:


The following code is directly from the spec:

int test(int i ...)
{
    return i;
}

void main()
{
        test(3);
}

The spec claims that "[a]n implementation may construct the object or array instance on the stack. Therefore, it is an error to refer to that instance after the variadic function has returned". This would seem to allow doing this for parameters which aren't object or array instances. Indeed, the spec gives the above code as an example of how "[f]or other types, the argument is built with itself".

I'd say DMD is in error here. I've yet to realise how "int test(int i ...)" is
any better or different from "int test(int i)", though.


-- 

November 18, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=560





------- Comment #1 from deewiant@gmail.com  2006-11-18 09:55 -------
Of course I forget to explain the bug itself. Currently, DMD errors out with:

asdf.d(5): Error: escaping reference to variadic parameter i


-- 

December 03, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=560


deewiant@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #2 from deewiant@gmail.com  2006-12-03 03:39 -------
Fixed in DMD 0.176.


--