must scope for delegates restrict compilation?
Daniel Kozak
kozzi11 at gmail.com
Thu Oct 3 12:32:42 UTC 2019
On Thu, Oct 3, 2019 at 2:00 PM Oleg B via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:
>
> Hello all
>
> I think this code must get compilation error, but it didn't,
> furthermore result program get UB.
>
> https://run.dlang.io/is/Qpr278
>
> Is this correct behavior and why?
when you change it a litle it seems works ok:
import std.stdio;
struct Foo
{
int delegate() dg;
void foo(return scope int delegate() dg)
{
this.dg = dg;
}
int call() { return dg(); }
}
Foo getFoo()
{
int x = 42;
Foo ret;
ret.foo(() => x);
return ret;
}
void main()
{
writeln(getFoo().call());
}
More information about the Digitalmars-d-learn
mailing list