DIP1000 scope inference

Quirin Schroll qs.il.paperinik at gmail.com
Tue Oct 25 14:14:00 UTC 2022


On Tuesday, 25 October 2022 at 02:09:02 UTC, Paul Backus wrote:
> For example, the `@trusted` function below is memory safe when 
> using the current compiler release, but will become unsafe when 
> compiled with DMD 2.101:
>
> ```d
> @trusted int[] example()
> {
>     scope example = [1, 2, 3];
>     return example;
> }
> ```
>
> The worst part is that the potential memory corruption is 
> introduced silently. Users who upgrade to DMD 2.101 will have 
> no idea that the ground has shifted beneath their feet until 
> their code invokes UB at runtime.

Asking curiously, wasn’t the function UB before, but the behavior 
changed?


More information about the Digitalmars-d mailing list