dmd 2.063 beta 5
Peter Alexander
peter.alexander.au at gmail.com
Thu May 23 03:16:59 PDT 2013
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.
More information about the Digitalmars-d-announce
mailing list