dip1000 and preview in combine to cause extra safety errors
Dukc
ajieskola at gmail.com
Wed Jun 8 15:10:53 UTC 2022
On Wednesday, 8 June 2022 at 14:52:53 UTC, Steven Schveighoffer
wrote:
> ```d
> string foo(in string s)
> {
> return s;
> }
>
> void main()
> {
> import std.stdio;
> string[] result;
> foreach(c; "hello")
> {
> result ~= foo([c]);
> }
> writeln(result);
> }
> ```
>
> Thoughts?
This is simply the result of using `in` wrong. `in` means `const
scope`. `scope` (without preceeding `return`) means you won't
return a reference to the address to the argument (unless the
function can reach it via some other channel). Result: undefined
behaviour.
More information about the Digitalmars-d
mailing list