[Issue 23175] -preview=in silently adds possible stack memory escape

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 16 02:44:35 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23175

--- Comment #8 from Steven Schveighoffer <schveiguy at gmail.com> ---
Let's look at foo written like this:

```d
string foo(const string s)
{
   return s;
}
```

Do you think there is any valid case where the compiler can be changed (even
behind a switch) to make this start corrupting memory, yet not give any warning
about it?

It is the same here. `in` means `const`. It's that way in the implementation,
it says that right in the spec. This is *valid* code, with an *expected*
meaning, and you are *changing the meaning* without warning.

You say that it's expected when you use -preview=in, because you specifically
used that switch. Does this mean preview in is never meant to be used on
existing code? Does this mean that at no time in the future will preview in be
turned on by default? I must assume this is a "preview" of what is to come. If
we never intend to make it a permanent semantic change, then we shouldn't call
it a "preview".

I do not think we need to change the semantics of preview=in, or to disable
optimizations based on it. What we need is a warning to tell the user that what
he wrote before, while valid with the previous compiler, has memory corruption
implications now that the semantics have changed.

--


More information about the Digitalmars-d-bugs mailing list