Thread overview
[Issue 23416] Difference DMD/GDC: Error: non-constant expression `& foo`
Oct 15, 2022
Iain Buclaw
Oct 15, 2022
kdevel
Dec 17, 2022
Iain Buclaw
October 15, 2022
https://issues.dlang.org/show_bug.cgi?id=23416

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |ibuclaw@gdcproject.org

--- Comment #1 from Iain Buclaw <ibuclaw@gdcproject.org> ---
LDC also errors:

dmd-gdc-difference.d(4): Error: need `this` to access `foo`
Compiler returned: 1

--
October 15, 2022
https://issues.dlang.org/show_bug.cgi?id=23416

--- Comment #2 from kdevel <kdevel@vogtner.de> ---
This code should compile and pass its unittest:

```post2.d
import std.stdio;
struct S {
   void function () fp = &foo;
   void foo ()
   {
      __PRETTY_FUNCTION__.writeln;
      fp = (&bar).funcptr;
   }
   void bar ()
   {
      __PRETTY_FUNCTION__.writeln;
      fp = (&foo).funcptr;
   }
   auto fun () // invocation helper
   {
      void delegate () dg;
      dg.ptr = &this;
      dg.funcptr = fp;
      return dg ();
   }
}

unittest {
   S s;
   s.fun;
   s.fun;
}
```

$ dmd -O -unittest -main -run post2 post2.d(3): Error: non-constant expression `& foo`

But this code should compile and pass:

$ gdc -O -funittest -fmain post2.d -o post2 && ./post2
void post2.S.foo()
void post2.S.bar()
1 modules passed unittests

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

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--
December 13
https://issues.dlang.org/show_bug.cgi?id=23416

--- Comment #3 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/20165

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--