New attribute to control references

Dennis dkorpel at gmail.com
Wed Apr 27 17:12:04 UTC 2022


On Wednesday, 27 April 2022 at 15:51:36 UTC, Loara wrote:
> this is not the point, the point is that with a not transitive 
> `scope` it's still possible to transfer references to non 
> `scope` pointers without explicit casts.

I think it's unclear what the example is demonstrating then.

If the point is "the lack of an error here shows a hole 
in`@safe`" then that's incorrect, because a function 
`stack_allocate!int(1);` can't return a scope pointer, and if you 
changed the signature so it could, dip1000 wouldn't allow you to 
assign it to `*b`.

If the point is "a transitive `scope` enables this pattern" then 
that's also incorrect, because you still can't actually implement 
`stack_allocate!int(1);`.

If, like you just clarified, the point is simply "`scope` isn't 
transitive", then that's correct, but that doesn't explain why 
there's a need for improvement in that regard.

> A transitive scope is more appropriate for `synchronized` 
> access to a `shared` variable that contains indirections rather 
> than a stack allocated object.

I've never thought about using `scope` in combination with shared 
data, but it's an interesting thing to consider.


More information about the Digitalmars-d mailing list