June 21, 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.
June 21, 2022
On Tuesday, 21 June 2022 at 17:33:46 UTC, H. S. Teoh wrote:
>
> Does the language allow you to declare a @system delegate inside @safe code?

Yes. This compiles:

    void main() @safe
    {
        void delegate() @system dg = () @system { /* do scary stuff */ };
    }
June 21, 2022

On 6/21/22 1:33 PM, H. S. Teoh wrote:

>

On Tue, Jun 21, 2022 at 01:29:47PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote:

>
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?

The code I wrote above compiles, even with dip1000. (note that I didn't actually call the delegate)

-Steve

June 21, 2022
On Tue, Jun 21, 2022 at 06:28:14PM +0000, Paul Backus via Digitalmars-d-learn wrote:
> On Tuesday, 21 June 2022 at 17:33:46 UTC, H. S. Teoh wrote:
> > 
> > Does the language allow you to declare a @system delegate inside @safe code?
> 
> Yes. This compiles:
> 
>     void main() @safe
>     {
>         void delegate() @system dg = () @system { /* do scary stuff */ };
>     }

Hmph. That does put a damper on my idea. :-(


T

-- 
One reason that few people are aware there are programs running the internet is that they never crash in any significant way: the free software underlying the internet is reliable to the point of invisibility. -- Glyn Moody, from the article "Giving it all away"
1 2
Next ›   Last »