[Issue 22907] New: Can't use core.lifetime.forward on inout parameter
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Mar 20 18:15:16 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22907
Issue ID: 22907
Summary: Can't use core.lifetime.forward on inout parameter
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: snarwin+bugzilla at gmail.com
As of DMD 2.099.0, the following program fails to compile:
---
inout(int)[] fun(inout(int)[] a)
{
import core.lifetime: forward;
return forward!a;
}
---
The error message is:
---
/dlang/dmd/linux/bin64/../../src/druntime/import/core/lifetime.d(1558): Error:
`inout` on `return` means `inout` must be on a parameter as well for `pure
nothrow @nogc @property @safe inout(int)[]()`
onlineapp.d(4): Error: template instance `onlineapp.fun.forward!(a)` error
instantiating
---
This happens because using core.lifetime.forward on a non-ref parameter creates
a zero-argument nested function that returns the parameter by value.
--
More information about the Digitalmars-d-bugs
mailing list