DIP1000 scope inference

Paul Backus snarwin at gmail.com
Tue Oct 25 15:41:18 UTC 2022


On Tuesday, 25 October 2022 at 14:14:00 UTC, Quirin Schroll wrote:
>
> Asking curiously, wasn’t the function UB before, but the 
> behavior changed?

Until very recently, the language spec [1] said that a `scope` 
*parameter* "must not escape", but was silent on whether the same 
rule applied to `scope` local variables (although it would be 
reasonable to infer that it did).

At some point between the release of DMD 2.100.2 and current 
`master`, the spec was updated to additionally state that 
returning a `scope` variable from a function is "disallowed" [2].

So, yes, I think the most reasonable interpretation is that this 
was always intended to be UB. But I am not confident that the 
average D user would have *known* for certain it was UB at the 
time DMD 2.100.2 was released.

[1] https://dlang.org/spec/function.html#scope-parameters
[2] https://dlang.org/spec/attribute.html#scope


More information about the Digitalmars-d mailing list