Bug 8227 – Anonymous member variable of struct get's it's arguments shifted when called.

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2012-06-11T14:32:06Z
Last change time
2024-12-13T18:00:28Z
Assigned to
No Owner
Creator
IdanArye
Moved to GitHub: dmd#18449 →

Comments

Comment #0 by GenericNPC — 2012-06-11T14:32:06Z
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 3.3.8-1.
Comment #1 by hsteoh — 2014-07-17T18:49:35Z
Hmm. On git HEAD, this code now produces this message: ---- test.d(3): Deprecation: variable test.S.foo const field with initializer should be static, __gshared, or an enum ---- Changing it to static, enum, or auto, doesn't exhibit the problem described.
Comment #2 by robert.schadek — 2024-12-13T18:00:28Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18449 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB