[Issue 24324] A default-initialized variable is not identical to its init value when it contains a default-initialized member variable that is a dynamic array

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 9 16:00:19 UTC 2024


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

Steven Schveighoffer <schveiguy at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at gmail.com

--- Comment #5 from Steven Schveighoffer <schveiguy at gmail.com> ---
Hm... what appears to be happening here is `S.init` is treated like an enum.

If you have an enum of an array, then it is like you typed in the literal
directly.

Mark main as `@nogc` and it fails (Because S.init allocates!)

Even `S s1 = S.init` allocates a new array on the heap.

This is quite unexpected, and I can't believe we haven't seen this before.

I tested via run.dlang.io, and this has happened at least as far back as 2.060.

--


More information about the Digitalmars-d-bugs mailing list