Bug 23021 – [dip1000] infer return scope from pure nothrow

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-04-16T10:36:22Z
Last change time
2022-04-18T06:33:48Z
Keywords
pull
Assigned to
No Owner
Creator
Dennis

Comments

Comment #0 by dkorpel — 2022-04-16T10:36:22Z
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`.
Comment #1 by dlang-bot — 2022-04-16T10:50:20Z
@dkorpel created dlang/dmd pull request #13993 "Fix issue 23021 - infer `return scope` from `pure nothrow`" fixing this issue: - Fix issue 23021 - infer `return scope` from `pure nothrow` https://github.com/dlang/dmd/pull/13993
Comment #2 by dlang-bot — 2022-04-18T06:33:48Z
dlang/dmd pull request #13993 "Fix issue 23021 - infer `return scope` from `pure nothrow`" was merged into master: - 80342bb59d8a85101f6fde5e00a57e23827af7f3 by Dennis Korpel: Fix issue 23021 - infer `return scope` from `pure nothrow` https://github.com/dlang/dmd/pull/13993