[Issue 24469] non-constant nested delegate literal expression - Error on delegates causing memory corruption

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 30 14:01:45 UTC 2024


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

kinke <kinke at gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kinke at gmx.net

--- Comment #2 from kinke <kinke at gmx.net> ---
Full example, showing the crash with DMD (LDC issues a compile error instead -
'Error: non-constant nested delegate literal expression `__lambda2`'):

```
struct ExistenceChecker
{
    bool delegate() checkExistenceFn;
}

ExistenceChecker makeExistenceChecker(string gemName)
{
    return ExistenceChecker(() => gemName == "dummy");
}

auto checker = makeExistenceChecker("test"); // => invalid non-constant
initializer

void main()
{
    assert(!checker.checkExistenceFn());
}
```

--


More information about the Digitalmars-d-bugs mailing list