[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
Mon Jan 8 18:12:06 UTC 2024


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

--- Comment #4 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
(In reply to Bastiaan Veelo from comment #2)
> I argue that it should be made an error to define an initializer of a
> non-shared non-static field that allocates. Thread:
> https://forum.dlang.org/post/ogvubzgprghefclgluce@forum.dlang.org
> 
> If you *want* the array to be shared across all instances, the field should
> be declared `shared static`.
> 
> In https://forum.dlang.org/post/t7vm2o$p4q$1@digitalmars.com, Steven notes
> that the array is shared among different threads, even, as discovered in
> https://issues.dlang.org/show_bug.cgi?id=2947.

It may very well be the best call to make cases like this illegal. However, I
think that requirement is going to have to take into account whether mutable
indirections are involved rather than just whether any allocations take place.
Otherwise, cases like SysTime's Rebindable!(immutable(TimeZone)) (which is
supposed to be default-initialized to a specific time zone so that the code
doesn't have to check for null, but it isn't due to another bug) become
illegal. The fact that the TimeZone itself is immutable avoids the issue,
whereas it would be an issue if TimeZone weren't immutable.

--


More information about the Digitalmars-d-bugs mailing list