[Issue 23021] New: [dip1000] infer return scope from pure nothrow
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Apr 16 10:36:22 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=23021
Issue ID: 23021
Summary: [dip1000] infer return scope from pure nothrow
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: dkorpel at live.nl
Currently, you can pass a scope pointer to a non-scope parameter if:
- the called function is pure nothrow
- there are no parameters with mutable indirections that can store pointers
- the called function's return type has no pointers / `ref`
```
@safe:
bool deref(int* x) pure nothrow;
void main()
{
int x;
deref(&x); // allowed to pass scope pointer
}
```
However, this doesn't work, because the third condition isn't met:
```
@safe:
int* identity(int* x) pure nothrow;
void main()
{
int x;
int* y = identity(&x); // y is now a scope pointer
}
```
Since the first two conditions are met, the compiler could infer `return scope`
on `identity` instead of `scope`.
--
More information about the Digitalmars-d-bugs
mailing list