www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8227] New: Anonymous member variable of struct get's it's arguments shifted when called.


           Summary: Anonymous member variable of struct get's it's
                    arguments shifted when called.
           Product: D
           Version: D2
          Platform: x86_64
               URL: http://stackoverflow.com/questions/10984930/creating-c
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: GenericNPC gmail.com

--- Comment #0 from IdanArye <GenericNPC gmail.com> 2012-06-11 14:32:06 PDT ---
I created a struct with an anonymous function member variable:
struct S
    const foo=function(int x,int y,int z)=>x;

When I create an instance of S and call the function with three arguments, the
arguments get shifted: x gets junk data, y gets the first argument, z gets the
second argument, and the third argument is lost.

If I declare foo in the global scope of the module, the arguments are passed
the way they should - x gets the first argument, y gets the second argument, z
gets the third argument.

If I declare foo as a member variable of a class, I get a segmentation fault
when I try to call foo.

Making foo a static, shared, or __gshared member does not solve the problem.

Declaring foo's type explicitly *DOES* solve the problem:
int function(int,int,int) foo=function(int x,int y,int z)=>x;
this does work.

I have encountered this bug on DMD64 D Compiler v2.059 running on Arch Linux

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