'scope' confusion
Loara
loara at noreply.com
Fri Apr 15 15:32:14 UTC 2022
On Friday, 15 April 2022 at 10:31:31 UTC, Dom DiSc wrote:
> On Friday, 15 April 2022 at 06:12:06 UTC, Paul Backus wrote:
>> No, because `scope` isn't transitive. [...]
>> That example does work. It's only when you get to two levels
>> of indirection that it fails; for example:
>>
>> ```d
>> @safe @nogc pure nothrow:
>>
>> void f() {
>> int x = 0;
>> scope int* y = &x;
>> scope int** z = &y; // error
>> }
>> ```
>
> If it's not transitive, perhaps we need something to make
> it explicit:
> ```d
> void f() {
> int x = 0;
> scope int* y = &x;
> scope int* scope* z = &y; // like const* in C++
> }
> ```
Actually the documentation is a bit confusing about `scope`
storage class and which operations are admitted for scoped
variables/function parameters. I think the role of `scope` inside
D is not well defined at this moment (and the original DIP1000
was written even worse) so until this feature will be fixed we
should avoid use it in released cose (and use `const` instead of
`in`)
More information about the Digitalmars-d
mailing list