[Issue 18058] @nogc and forwarding lazy argument, particularly with scope

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Dec 11 19:39:28 UTC 2017


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

Seb <greensunny12 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greensunny12 at gmail.com

--- Comment #2 from Seb <greensunny12 at gmail.com> ---
FWIW that attributes are set wrongly on lazy parameters and their function is a
well-known bug and has been around for a long time. See e.g. issue 12647
(there's quite a list of duplicates attached to it). There even have been two
PRs (see issue 12647 for a list) aimed at fixing them, but they didn't tackle
the root problem.


The problem becomes easy to inspect if one uses the hidden -vcg-ast flag at the
compiler.

For the example linked at 

--
import object;
void assertThrown(E)(lazy E expression)
{
        expression();
}
void main()
{
        assertThrown(delegate int() => 0);
        return 0;
}
assertThrown!int
{
        pure @safe void assertThrown(lazy int expression) // <- should have
nothrow
        {
                expression();
        }

}
---

For yours:

---
import object;
@nogc void func1(lazy scope string msg)
{
}
void func2(lazy scope string msg)
{
        func1(delegate string() => msg()); // <- lambda doesn't have @nogc
}
---

--


More information about the Digitalmars-d-bugs mailing list