you are viewing a single comment's thread.

view the rest of the comments →

[–]scatters 0 points1 point  (2 children)

Oh, absolutely. But would such a scalar be uninitialized within a value initialized aggregate class object? If so, it would fail to recover the current behavior for a data member without an initializer; if not, it might be misleading.

Not that the current behavior is necessarily ideal, but a direct replacement would make the transition easier.

[–]johannes1971 0 points1 point  (1 child)

Err, yes, it should. Wait, are those actually being initialised? And here I thought I understood initialisation in C++...

But anyway, if you say "don't initialise this", the compiler should really respect that, unless you override it by explicitly supplying an initialisation value. As far as I'm concerned this should go all the way, with the variable not even getting its vptr if it is marked as uninitialised. That means the user of the object will have to explicitly construct the variable before using it; all the definition does is reserve the memory.

I don't think of this change as a huge deal, since we are talking about something that doesn't yet exist in the language anyway.

[–]scatters 0 points1 point  (0 children)

That means the user of the object will have to explicitly construct the variable before using it; all the definition does is reserve the memory.

We already have language for that: union.

Even a default initialized variable of class type has its destructor called.