dmd 2.063 beta 5

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu May 23 08:45:45 PDT 2013


On 5/23/13 6:16 AM, Peter Alexander wrote:
> On Thursday, 23 May 2013 at 09:05:02 UTC, Don wrote:
>> This means that the const variable x has been initialized TWICE!
>
> That's no different from non-const members.
>
> struct Foo { int x = 1; }
> Foo f = Foo(2); // f.x is 2
>
> The initialiser is a default value if you don't provide one in the
> constructor. If you don't mark a variable as static then it is not
> static and needs to be initialised like any other member variable.
>
>
>> This new behaviour is counter-intuitive and introduces a horrible
>> inconsistency.
>
> It is exactly what happens in C++ and causes no confusion there.
>
>
>> This is totally different to what happens with module constructors
>> (you get a compile error if you try to set a const global if it
>> already has an initializer).
>
> In structs/classes, it is not an initialiser, it is a default value in
> case you don't provide a different value.
>
>
>> As far as I can tell, this new feature exists only to create bugs. No
>> use cases for it have been given. I cannot imagine a case where using
>> this feature would not be a bug.
>
> The use case is simple: to allow non-static const member variables.

The point is, this is a silent change of behavior. (I agree the new 
behavior is sensible.)

Andrei


More information about the Digitalmars-d-announce mailing list