D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23191 - [dip1000] scope parameter can be returned in @system code
Summary: [dip1000] scope parameter can be returned in @system code
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-06-16 08:55 UTC by Dennis
Modified: 2022-06-16 10:06 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dennis 2022-06-16 08:55:24 UTC
`scope` checks are only enabled in @safe code because they might have false positives, and we don't want to break valid @system code, where we trust the programmer to get it right. 

However, blatantly returning a `scope` parameter could still be made an error. This is useful since @system is still the default and `scope` may be hidden behind `in`.

```
int* f(scope int* x)
{
    return x;
}

const(int)* f(in int* x) // with -preview=in, it means `const scope`
{
    return x; // may look innocuous
}
```

This came up in the news group:
https://forum.dlang.org/post/t7rfdm$1jjc$1@digitalmars.com
https://forum.dlang.org/post/t88iuv$mbb$1@digitalmars.com
Comment 1 Dlang Bot 2022-06-16 08:58:20 UTC
@dkorpel created dlang/dmd pull request #14221 "Fix 23191 - scope parameter can be returned in `@system` code" fixing this issue:

- Fix 23191 - scope parameter can be returned in `@system` code

https://github.com/dlang/dmd/pull/14221
Comment 2 Dlang Bot 2022-06-16 10:06:54 UTC
dlang/dmd pull request #14221 "Fix 23191 - scope parameter can be returned in `@system` code" was merged into master:

- d72e596128d4fc0ab928e3e86520e7d2fa54d14a by Dennis Korpel:
  Fix 23191 - scope parameter can be returned in `@system` code

https://github.com/dlang/dmd/pull/14221