News for hackers. Stuff that matters.
Re:C++26 is done ISO C++ standards meeting, Trip Report by WalterBright on Monday March 30, 2026 @12:32AM (#47570410)
D initializes all variables. If you don't provide an initializer, the compiler inserts the default initializer for it.

But if you really, really want to leave it uninitialized, write:

    int x = void;
where you're not writing that by accident.
Re:C++26 is done ISO C++ standards meeting, Trip Report by Negitivefrags on Monday March 30, 2026 @12:55AM (#47570524)
That is a way better syntax. I wonder why C++ didn't adopt it.
Re:C++26 is done ISO C++ standards meeting, Trip Report by jcalvinowens on Monday March 30, 2026 @01:33AM (#47570711)
Re:C++26 is done ISO C++ standards meeting, Trip Report by WalterBright on Monday March 30, 2026 @03:27AM (#47571459)
I don't understand its claim of a "self-documentation trap".

I'm surprised the "= void;" wasn't discussed. People liked it immediately in D, and other alternatives were not proposed.

Re:C++26 is done ISO C++ standards meeting, Trip Report by saagarjha on Monday March 30, 2026 @05:36AM (#47572274)
The syntax is probably fine but I feel that the default kind of sucks; default initialization has mostly fallen out of favor these days.
Re:C++26 is done ISO C++ standards meeting, Trip Report by bluGill on Monday March 30, 2026 @09:23AM (#47573978)
Because you can't adopt that syntax after the fact. there is 30 years of C++ in the real world, initializing everything by default unless you opt-in will break some performance critical code that should not initialize everything (until it is updated manually - it has to be manual because tools are not smart enough to know where something was intentionally not initialized 100% of the time)

Thus the current erroneous. It means this isn't a bug (compilers used to optimized out code paths where an uninitialized value is read and this did cause real world bugs when it doesn't matter what value is read). It also means the compiler is free to put whatever value they want there - one of the goals was the various sanitizers that check for using uninitialized values need to still work - the vast majority of the time when an uninitialized value is read that is a bug in the code.

There are a lot of situations where a compiler cannot tell if a variable would be used uninitialized, so we can't rely on compiler warnings (it sometimes needs solving the halting problem).

Re:C++26 is done ISO C++ standards meeting, Trip Report by tialaramex on Monday March 30, 2026 @09:44AM (#47574260)
> There are a lot of situations where a compiler cannot tell if a variable would be used uninitialized, so we can't rely on compiler warnings (it sometimes needs solving the halting problem).

It's an explicit choice in C++ to always accept correct programs (the alternative being to always reject incorrect programs†). The committee does not have to stick by this bad decision in each C++ version, of course they aren't likely to stop making the same bad choice, but it is possible to do so.

If you're allowed to take the other side, you can of course (Rust and several other languages do this) reject programs where the compiler isn't satisfied that you definitely always initialize the variable before it's value is needed. Most obviously (but it's pretty annoying, so Rust does not do this) you could insist on the initialization as part of the variable definition in the actual syntax.

† You can't have both, by Rice's Theorem, Henry Rice got his PhD for figuring out how to prove this, last century, long before C++ was conceived. So you must pick, one or the other.

Re:C++26 is done ISO C++ standards meeting, Trip Report by aw1621107 on Monday March 30, 2026 @10:03AM (#47574512)
> there is 30 years of C++ in the real world, initializing everything by default unless you opt-in will break some performance critical code that should not initialize everything

...But the change to EB in this case does initialize everything by default?

Re:C++26 is done ISO C++ standards meeting, Trip Report by bluGill on Monday March 30, 2026 @10:59AM (#47575186)
No it doesn't. It says the value is unspecified but it exists. Sometimes some compilers did initialize everything (this was common in debug builds) before. Some of them will in the future, but most won't do anything difference.

The only difference is some optimizer used to eliminate code paths where they could prove that path would read an uninitialized variable - causing a lot of weird bugs in the real world.

Re:C++26 is done ISO C++ standards meeting, Trip Report by aw1621107 on Monday March 30, 2026 @12:39PM (#47576544)
> It says the value is unspecified but it exists.

The precise value is not specified, but whatever value is picked also has to be something that isn't tied to the state of the program so some kind of initialization needs to take place.

Furthermore, the proposal explicitly states that (some) variables are initialized by default:

> Default-initialization of an automatic-storage object initializes the object with a fixed value defined by the implementation

> The automatic storage for an automatic variable is always fully initialized, which has potential performance implications.

> The automatic storage for an automatic variable is always fully initialized, which has potential performance implications.

Re:C++26 is done ISO C++ standards meeting, Trip Report by WalterBright on Monday March 30, 2026 @04:41PM (#47579463)
> Because you can't adopt that syntax after the fact.

The `= void` syntax can be because it is currently not valid.

D (unlike C++) always has a default initializer, but does not allow a default constructor. This is sometimes controversial, but it heads off all kinds of problems.

The default initializer for floating point values is NaN. (And for chars it is 0xFF.) The point of this is for the value to not "happen" to work.)

Re:C++26 is done ISO C++ standards meeting, Trip Report by tialaramex on Monday March 30, 2026 @09:31AM (#47574061)
> If you don't provide an initializer, the compiler inserts the default initializer for it.

This requires that there is a default. Several modern languages (such as Go) insist on this, it means now your types don't even model reality in this very fundamental way. Who is a person's default spouse? Even where you can imagine a default it's sometimes undesirable to have one, for example we already live in a society where somebody decided default gender is male - and it might look too much like real data, default birthday being 1 January also matches hundreds of thousands of Americans...

The most likely place you go after "Everything has a default" is the billion dollar mistake because you're inclined to just incorporate "or it's default invalid" into the type definition to get your default, and when you do that everywhere needs to have "check it's valid" code added, even if we already just checked that a moment ago.

Re:C++26 is done ISO C++ standards meeting, Trip Report by kwsp on Monday March 30, 2026 @10:36AM (#47574934)
I don’t care that much about everything having a default (although it’s nice), but if a language insists on a default value for every type for safety, can’t you just use std::optional?
Re:C++26 is done ISO C++ standards meeting, Trip Report by tialaramex on Monday March 30, 2026 @11:42AM (#47575724)
I can't tell if you imagine std::optional is a value (it is not) or if you know it's a templated type but you imagine that somehow it would be OK to redefine all programs so that every type is std::optional<T> of that type instead so as to simplify initialization.

Either way no, that can't work.

Re:C++26 is done ISO C++ standards meeting, Trip Report by MaxBarraclough on Tuesday March 31, 2026 @04:50PM (#47593306)
> Either way no, that can't work.

Kotlin has explicit nullable types. Rust has no null, but has option types. Both languages work fine.

I think your point was that neither approach could reasonably be retrofitted to C++, do I have that right?

Re:C++26 is done ISO C++ standards meeting, Trip Report by tialaramex on Wednesday April 01, 2026 @06:35AM (#47599085)
Rust works fine because types are not required to have a default, if you want your type to have a default you implement Rust's Default trait. Stuff which only makes sense if there's a default just depends on that trait and so won't be available, for example you can't core::mem::take your custom Goose type which has no default because core::mem::take<T: Default>. In Rust if we say there's a variable of type Goose and don't initialize it, it's not initialized, and if the compiler can't see why it's initialized before it's used the program is rejected as nonsense because Rust is a safe language and that's an unsafe outcome.

I don't write Kotlin, so I can't speak to the details there.

C++ like Rust does not require that types have a default. In C++ the way you provide a "default" is usually via a zero argument constructor, since the compiler can just call that wherever you asked for an instance of that type and there's no requirement to write such a constructor, or indeed to provide any public constructor at all. So "just use the default" could not work in C++ as it exists today yes.

The other reason C++ can't do anything like this is that it makes a newer C++ with this behaviour behave differently despite no syntactical change. Rust is OK with that, because it has the Edition system to differentiate Rust 2015 code which means one thing from Rust 2024 code which means something else despite having the same text, but in C++ they do not have anything like that, it's not rare for somebody's C++ 17 code to get compiled in C++ 23 and people expect that to work (it doesn't always work but that's what they expect).

Re:C++26 is done ISO C++ standards meeting, Trip Report by inetknght on Monday March 30, 2026 @11:14AM (#47575376)
I often see arguments like yours. I reject them wholeheartedly. Your argument is pro-poor-design. I tell you: design your software better. Design your software so that you can't have undefined behavior. It's harder, yes. LLMs suck at it, yes. But building well-designed software is a significant part of being a better engineer.
Re:C++26 is done ISO C++ standards meeting, Trip Report by steveklabnik on Monday March 30, 2026 @12:31PM (#47576414)
It is easier to design the software so that you don't have confusing behavior when you're not required to include behaviors you don't want. Most things do not need to be nullable. Requiring all things to have a zero value, even when they do not have one, makes it harder to be correct by construction, not easier.
Re:C++26 is done ISO C++ standards meeting, Trip Report by WalterBright on Monday March 30, 2026 @04:58PM (#47579623)
> Requiring all things to have a zero value

D default initializes floats to NaN.

Re:C++26 is done ISO C++ standards meeting, Trip Report by inetknght on Monday March 30, 2026 @09:19PM (#47581679)
> It is easier to design the software so that you don't have confusing behavior when you're not required to include behaviors you don't want.

It can be easier, but not always. But it is almost always a better design.

Redesigning software so that whole classes of problems simply can't exist is absolutely better than software that needs to handle all kinds of problems. Many of those problems might not even ever happen in real circumstances!

> Requiring all things to have a zero value, even when they do not have one, makes it harder to be correct by construction, not easier.

Don't require a "zero value". Require a "correctly-constructed" value. Sometimes zero is correctly constructed, sometimes not.

Re:C++26 is done ISO C++ standards meeting, Trip Report by steveklabnik on Tuesday March 31, 2026 @05:47PM (#47593924)
I agree that you want to require a correctly-constructed value. The entire point I'm making is that in languages with zero values, this is hard, because that zero value may not be valid for your domain.

Languages with pervasive nullability effectively gives everything a zero value.