r/cpp • • Sep 27 '26

You should think about recompiling your C++ programs with GCC 16 and C++26, because it zero-fills your locals

https://techfortalk.co.uk/2026/09/27/cxx26-uninitialized-local-variables-gcc-16/

Stack variables are not automatically initialised, and that is the root cause of many C++ bugs. That is well known. Hence, it is advised that local or stack variables are always initialised with known values, 0 if not something more meaningful than that. Now, with GCC 16 compiling in C++26 mode (-std=c++26), even uninitialised local variables will be zero-filled. In the post, I have explained how.

270 Upvotes

234 comments sorted by

View all comments

Show parent comment

1

u/NilacTheGrim Oct 15 '26

it can be done,

Again, violating encapsulation. What this means in practice is you need to "bubble out" the [[indeterminate]] to every use of the class, and all classes that use that class, and all classes that use those classes -- at every usage.

Bottom line is there is no practical escape.

This is strictly a downgrade of the C++ language. What is the win here? Code that is wrong stays wrong but gets swept under the rug with this.

This is a failure of the committee and a misfeature of the language. I hope they remove this in C++29 or whatever.

I will be compiling with this disabled if/when we transition to C++26.

1

u/Spartan322 Oct 16 '26

Again, violating encapsulation.

Okay cool, I really could not care less about violating encapsulation, it can be done, that's the end of it and that's my point, the dogma of encapsulation can take a hike. I sparely use encapsulation, it barely (if at all) exists in C, and too often it gets in my way in C++ to use it as anything more then the occasional tool just the same as how I use singletons and the observer pattern, its great when it doesn't get in my way, worthless when it does. Doing something well and efficient is not subscribing to one paradigm, pattern, or tool, (especially as dogma) and sometimes is actively abandoning the ones that cost you for the workload. And encapsulation is one that's certainly done that to me.

1

u/NilacTheGrim Oct 16 '26

We're arguing past each other. My argument is that this stinks, and there is no escape. Stop being stuck on the word encapsulation.

The point is that it is a code smell that this exists now and a downgrade for the language with no escape.

Arguing that you can escape it -- is just not taking into account what escaping it entails. It entails "coloring" everything that ever touches code that needs uninitialized (non-dynamic) memory.

Anyway, have a nice day.