www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20501] New: Function literals inside enum of function

https://issues.dlang.org/show_bug.cgi?id=20501

          Issue ID: 20501
           Summary: Function literals inside enum of function pointers
                    wrongly treated as delegates
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kinke gmx.net

The following program compiles fine but is killed at runtime, as it tries to
jump to an invalid instruction address:

```
enum E : void function()
{
    First = () {} // `= function() {}` works
}

void main()
{
    E.First(); // invalid jump
}
```

run.dlang.io Linux x64 asm:

_Dmain:
        push    RBP
        mov     RBP,RSP
        mov     RCX,pure nothrow  nogc  safe void
onlineapp.E.__lambda2() GOTPCREL[RIP]
        xor     EAX,EAX // btw, why 32-bit only?
        call    RAX
        xor     EAX,EAX
        pop     RBP
        ret

--
Jan 12