Fixing tail mutable TLS/field initializers

Steven Schveighoffer schveiguy at gmail.com
Mon Jun 10 21:00:18 UTC 2024


On Friday, 7 June 2024 at 11:05:03 UTC, Nick Treleaven wrote:

> Given that we will have editions, ideally we would disallow any 
> tail mutable initializer for both fields and thread-local 
> variables. They are bug-prone - use a constructor instead if a 
> unique initializer is intended.

Yes!

As far as TLS is concerned, I think tail-shared is fine to allow 
as well.

For fields, yeah, we should just eliminate initializers that 
contain pointers to mutable data. Nobody expects what happens, 
even seasoned D programmers.

> One reason why we might not want to disallow them is if it 
> makes porting existing code to the next edition too awkward. So 
> we would need to investigate that.

Making it harder to create bugs is a plus, even if it breaks 
previously buggy code.

-Steve


More information about the dip.ideas mailing list