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: [email protected]
Reporter: [email protected]
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`.
--