Thread overview
[Issue 17315] Assigning a delegate to a function compiles but causes segfault
Dec 17, 2022
Iain Buclaw
May 18, 2023
RazvanN
May 18, 2023
Eyal
May 18, 2023
RazvanN
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=17315

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

--
May 18, 2023
https://issues.dlang.org/show_bug.cgi?id=17315

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |razvan.nitu1305@gmail.com
         Resolution|---                         |WORKSFORME

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
I cannot reproduce this. It compiles and runs successfully. When you are taking the address of _load the currently returns a function pointer (set to the actual code of the function in the .text section). This behavior is reported as being a bug in previous bug reports (such as https://issues.dlang.org/show_bug.cgi?id=3720). So, since the segfault no longer manifests, this bug report is resolved.

--
May 18, 2023
https://issues.dlang.org/show_bug.cgi?id=17315

Eyal <eyal@weka.io> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |eyal@weka.io
         Resolution|WORKSFORME                  |---

--- Comment #2 from Eyal <eyal@weka.io> ---
A small change to _load to make it actually use the incorrect "this" shows it's still broken:

    import std;

    class Base {
        __gshared static Base function()[string] registry;
        static Base load(string name) {return registry[name]();}
    }

    class Child: Base {
        shared static this() {
            registry[__traits(identifier, typeof(this))] = &_load;   // <<<
this shouldn't compile
        }

        int x = 1;
        Base _load() {
            assert(x == 1, x.text);     //
core.exception.AssertError@dtest.d(15): 1970086008
            return new typeof(this);
        }
    }

    void main() {
        auto inst = Base.load("Child");  // segfault
    }

--
May 18, 2023
https://issues.dlang.org/show_bug.cgi?id=17315

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
Yes, then it's a dupe of 3720

*** This issue has been marked as a duplicate of issue 3720 ***

--