destroy and @safe

H. S. Teoh hsteoh at qfbox.info
Tue Jun 21 17:33:46 UTC 2022


On Tue, Jun 21, 2022 at 01:29:47PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote:
> On 6/21/22 1:17 PM, H. S. Teoh wrote:
[...]
> > This is why I've proposed in the past that @safe functions should be
> > allowed to call @system delegates that they receive as arguments. The
> > reasoning goes like this: if the delegate was in fact @safe (i.e., it's
> > a @safe delegate passed to a @system parameter -- @safe is covariant
> > with @system), then there is no problem. If the delegate was @system,
> > then the caller can only have been called from @system somewhere up the
> > call stack (@safe code can't create @system delegates), so we're also
> > OK: if the caller was @system, then we guarantee nothing anyway.
> > However, Walter didn't seem convinced by this proposal.
> 
> ```d
> void foo(void delegate() @system dg) @safe {
>    int *bar;
>    @system void corrupt() { bar = cast(int *)0xdeadbeef;}
>    dg = &corrupt;
>    // can I call dg now?
> }
> ```
[...]

Does the language allow you to declare a @system delegate inside @safe
code?


T

-- 
Being able to learn is a great learning; being able to unlearn is a greater learning.


More information about the Digitalmars-d-learn mailing list