[dmd-beta] dmd 2.064 beta take 2

Jonathan M Davis jmdavisProg at gmx.com
Wed May 15 10:07:07 PDT 2013


On Wednesday, May 15, 2013 16:11:03 Don Clugston wrote:
> > You kind of propose that "const int" to be a completely different type
> > depending on initialiser. It is horrible.
> 
> I have not said that. I've asserted that const member with an initializer,
> when inside a struct, is ALWAYS a bug.
> I agree that we need to get rid of the existing behaviour. But I argue it
> should simply be an error, rather than replacing it with a misfeature.

Indeed. It really makes no sense to have const or immutable members in a 
struct. You simply render the struct completely useless under a variety of 
circumstances, because it can't ever be reassigned. It's one thing to create a 
const or immutable instance of a struct. It's quite another to have a single 
member which is const or immutable. You might as well just make such a member 
static.

Now, as useless as it is, it's perfectly consistent with the rest of the 
language to have const or immutable members actually be part of the struct 
layout rather than effectively being treated as implicitly static, and the old 
behavior is definitely inconsistent with the rest of the language. But given 
how this will silently break who knows how much code, it's a terrible change. 
It would be far better to just disallow it.

- Jonathan M Davis


More information about the dmd-beta mailing list