C++23 adds several safety features.
std::stacktrace — debugging:
1#include <stacktrace>2auto st = std::stacktrace::current();3std::cout << st; // Print call stack
std::expected — error handling:
1std::expected<int, std::string> parse(const std::string& s);2auto result = parse("42");3if (result) std::cout << *result;
Deduping this — prevent dangling:
1class Foo {2 auto bar() const { return *this; } // Deduced this3};
if consteval — compile-time check:
1constexpr int process(int x) {2 if consteval {3 return x * 2;4 } else {5 return x * 3;6 }7}
std::unreachable — optimization:
1if (impossible) {2 std::unreachable(); // UB if reached3}
Benefits: