The following is from the knowledge and expertise of a self-taught programming hobbyist:
The more problems in code that can be caught at compile time is a good thing, even if it requires a bit of safety scaffolding to achieve.
An example....
std::format before P2216R3 (
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2216r3.html)
A malformed formatting string compiled just fine without problems, at least with VS2019/2022. To catch any possible boo-boos using try/catch blocks was required. Or watch the program crash. Requiring debugging to discover why and where everything fell down and went *BOOM!*
After this proposal was applied to the C++ standard now a malformed formatting string won't compile. No need for exception handling, at least for formatting.
The few examples of C++ Safety scaffolding I see in the proposal is somewhat akin to the Desktop WinAPI SAL notation.
https://learn.microsoft.com/en-us/cpp/code-quality/understanding-sal?view=msvc-170
M'ok, someone is not
required to use SAL to document WinAPI code, if it is missing the MSVC compiler merely whinges and still creates an executable.
The C++ Safety proposal merely ups the checking for potential run-time problems at what appears to be compile-time, reporting hazards before they are released into the wild. Using it won't likely be required, but like the C++ Core Guidelines it could be a damned good recommendation for creating more robust code with minimal fuss.
At least that is my take on what I read is being proposed. I could be wrong. ¯\_(ツ)_/¯
I'm comfortable with using SAL for WinAPI code, from what I've seen of how to use C++ Safety it wouldn't be a huge burden to use going forward after adoption. Every C++ standard IMO changes the language and helps make it better for the most part.
Even the back and forth method for lambda capture of the
this pointer between C++ stdlib versions.
cppreference wrote: |
---|
1 2 3 4 5 6 7 8 9 10
|
struct S2 { void f(int i); };
void S2::f(int i)
{
[=] {}; // OK: by-copy capture default
[=, &i] {}; // OK: by-copy capture, except i is captured by reference
[=, *this] {}; // until C++17: Error: invalid syntax
// since C++17: OK: captures the enclosing S2 by copy
[=, this] {}; // until C++20: Error: this when = is the default
// since C++20: OK, same as [=]
}
|
|
(Yes, I do understand the difference between
*this and
this, m'ok? And the reasoning behind the usage difference. I merely find it interesting lambda capture of
this changed between standards.)
*Back to my lounge chair and pop-corn....*