Tuesday, December 23, 2025

Thoughts on C++ 26

Sutter's video

 The other day I watched Sutter's YouTube video about 3 cool things in C++ 26:

  1. Make C++ safer by replacing undefined behavior (UB) with erroneous behavior (EB)
  2. Reflection
  3. Yet another syntax for async

Safe C++ 

Sutter mentions two aspects:

  • uninitialized local variables will be data mangled. The compiler may inject code to check if uninitialized variables are accessed.
  • hardening of STL; most notably operator[] 
According to studies the overhead is minimal (0.3%). This number is debatable: they can never know what applications are out there. In the past we had bad experience with VS 2008 who turned on safe iterators in release builds. That killed all compiler optimizations around iterators when used.

I question also the first bullet: why not make it simpler and state that every variable will be default or zero initialized. There is no EB or UB necessary; or no hidden code injected by the compiler.

Some of the hardened STL functions are unnecessary. There are already 'at()' functions which bounds check. A safety profile could warn for use of operator[].

Reflection

Nice that reflection is added but I wonder if the C++ committee has the right priorities. The standard library even lacks a standard JSON or XML library which would be an ideal candidate for automatic serialization through reflection.

Async

They added a new superfluous new syntax. So much for consistency.

 Conclusion

 Guaranteed memory safety is an important issue these days for certain domains. It is also good for silencing the Rust religion. The C++ committee should offer something though not sure if this is the way by changing the language fundamentally for everyone. Even so I would go then for zero initialization instead of checks with hidden costs. Reflection is nice but what C++ lacks most is more standard libraries; not major language changes. For me as a developer of desktop applications without internet connectivity memory safety is not important.

No comments:

Post a Comment

Watch out for YouTube commenting

YouTube comments  I am quite hooked to YouTube movies and share sometimes my thoughts or opinion in the comment section. I am always factual...