In the world of systems programming, C++ remains one of the most powerful and widely used languages, primarily because of its unmatched performance and fine-grained control over hardware. However, C++ also has a reputation for being notoriously difficult to manage safely. Memory leaks, buffer overflows, undefined behavior, and other issues can easily arise if programmers don’t carefully follow best practices, leading to vulnerabilities and bugs in production systems. This is where efforts like those of Sean Baxter and the C++ Alliance come into play, focusing on improving C++ safety through innovation, tools, and community initiatives.
Continue reading “Sean Baxter and the C++ Alliance: Leading the Charge for C++ Safety”Tag: C++ Safety
Could Herb Sutter’s call to action for C++ safety be acheived soon?
Recently, Herb Sutter wrote an excellent article on C++ safety. He discussed numerous ideas, but I’ll provide a summary of his perspective on what can be done in the medium term to enhance C++ safety.
In C++, by default enforce … | (A) Solution for new/updated code (can require code changes — no link/binary changes) | (B) Solution for existing code (requires recompile only — no manual code changes, no link/binary changes) |
Type safety | Ban all inherently unsafe casts and conversions | Make unsafe casts and conversions with a safe alternative do the safe thing |
Bounds safety | Ban pointer arithmetic Ban unchecked iterator arithmetic | Check in-bounds for all allowed iterator arithmetic Check in-bounds for all subscript operations |
Initialization safety | Require all variables to be initialized (either at declaration, or before first use) | — |
Lifetime safety | Statically diagnose many common pointer/iterator lifetime error cases | Check not-null for all pointer dereferences |
Less undefined behavior | Statically diagnose known UB/bug cases, to error on actual bugs in existing code with just a recompile and zero false positives: Ban mathematically invalid comparison chains (add additional cases from UB Annex review) | Automatically fix known UB/bug cases, to make current bugs in existing code be actually correct with just a recompile and zero false positives: Define mathematically valid comparison chains Default return *this; for C assignment operators that return C& (add additional cases from UB Annex review) |
But what are the current possibilities for achieving this goal?
Continue reading “Could Herb Sutter’s call to action for C++ safety be acheived soon?”