Thread overview
[Issue 23515] Named Enum of function SIGSEGFAULT
Dec 17, 2022
Iain Buclaw
Dec 17, 2022
Iain Buclaw
Jan 02, 2023
Basile-z
Jan 08
RazvanN
Jan 30
Dlang Bot
Jan 30
Dlang Bot
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=23515

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=23515

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P4                          |P2
           Severity|enhancement                 |major

--
January 02, 2023
https://issues.dlang.org/show_bug.cgi?id=23515

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |backend, wrong-code
                 CC|                            |b2.temp@gmx.com
           Hardware|x86                         |All
                 OS|Windows                     |All

--
January 08
https://issues.dlang.org/show_bug.cgi?id=23515

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
As a workaround you can name the anonymous function and it works:

```
void fun() {}

enum Easing : void function()
{
    identity = &fun
}
void main()
{
    Easing.identity();
}
```

This is just to unblock you, I'm looking now into how to make it work as is.

--
January 08
https://issues.dlang.org/show_bug.cgi?id=23515

--- Comment #2 from Marcelo Silva Nascimento Mancini <msnmancini@hotmail.com> ---
Hello RazvanN.
The solution I'm currently using, is by using this templated style:

```d
//TODO: Change (x) to (float x) for not generating templates needlessly
enum HipEasing : float function(float x)
{
    identity        = (x) => x,
}
```
I hope it may help in the bug lookup

--
January 23
https://issues.dlang.org/show_bug.cgi?id=23515

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
It looks like `identity` is being set to null, and the lambda is ignored.

--
January 23
https://issues.dlang.org/show_bug.cgi?id=23515

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
Here's the generated code (renaming main() to test()):

_D5test16Easing9__lambda2MFNaNbNiNfZv:
0000:   C3                       ret    // the lambda

_D5test14testFZv:
0000:   55                       push      RBP
0001:   48 8B EC                 mov       RBP,RSP
0004:   B9 00 00 00 00           mov       ECX,0
0009:   31 C0                    xor       EAX,EAX
000b:   48 FF D0                 call      RAX
000e:   5D                       pop       RBP
000f:   C3                       ret

Calling null will definitely seg fault.

--
January 23
https://issues.dlang.org/show_bug.cgi?id=23515

--- Comment #5 from Walter Bright <bugzilla@digitalmars.com> ---
The difference between identity being an (){} vs &fun is the first is a direct function call the second is an address of a function.

I'm not sure yet if the former should be an error, or can be made to work. Having an enum of function names has never occurred to me.

--
January 30
https://issues.dlang.org/show_bug.cgi?id=23515

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
@WalterBright created dlang/dmd pull request #16117 "bugzilla Issue 23515 - Named Enum of function SIGSEGFAULT " mentioning this issue:

- bugzilla Issue 23515 - Named Enum of function SIGSEGFAULT

https://github.com/dlang/dmd/pull/16117

--
January 30
https://issues.dlang.org/show_bug.cgi?id=23515

Dlang Bot <dlang-bot@dlang.rocks> changed:

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

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #16117 "fix bugzilla Issue 23515 - Named Enum of function SIGSEGFAULT " was merged into master:

- e957b77fb7d5c250554c10b8c16bb5112b22f07d by Walter Bright:
  fix bugzilla Issue 23515 - Named Enum of function SIGSEGFAULT

https://github.com/dlang/dmd/pull/16117

--