Thread overview
[Issue 23815] closure allocated even if the escape is opnly used to access static members
Mar 29, 2023
Basile-z
[Issue 23815] closure allocated even if the escape is only used to access static members
Mar 29, 2023
Basile-z
Mar 29, 2023
Salih Dincer
Mar 29, 2023
Basile-z
Apr 13, 2023
Basile-z
Apr 13, 2023
Richard Cattermole
March 29, 2023
https://issues.dlang.org/show_bug.cgi?id=23815

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--
March 29, 2023
https://issues.dlang.org/show_bug.cgi?id=23815

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|closure allocated even if   |closure allocated even if
                   |the escape is opnly used to |the escape is only used to
                   |access static members       |access static members

--
March 29, 2023
https://issues.dlang.org/show_bug.cgi?id=23815

Salih Dincer <salihdb@hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |salihdb@hotmail.com

--- Comment #1 from Salih Dincer <salihdb@hotmail.com> ---
No problem, the code compiles for me:

alias T = int;

class C
{
  static T i;
  this(T n) { i = n; }
}

alias fo = T function();  // not compile
alias foo = T delegate(); // compile

auto ID(C c)
{
  foo f = () => c.i;
  return f();
}

void main()
{
  auto test = new C(42);
  assert(test.ID == 42);
}

--
March 29, 2023
https://issues.dlang.org/show_bug.cgi?id=23815

--- Comment #2 from Basile-z <b2.temp@gmx.com> ---
> No problem, the code compiles for me:

It's not a bug report, it's about the fact that the front-end add the code to allocate a closure that's useless. Then it is eventually optimized away but in first place it should not even be there, even without optimz.

--
April 13, 2023
https://issues.dlang.org/show_bug.cgi?id=23815

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=23835

--
April 13, 2023
https://issues.dlang.org/show_bug.cgi?id=23815

Richard Cattermole <alphaglosined@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alphaglosined@gmail.com
         Resolution|---                         |DUPLICATE

--- Comment #3 from Richard Cattermole <alphaglosined@gmail.com> ---
Let's mark this one as a duplicate, as the other issue has an explanation from Razvan about why it doesn't work.

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

--