Add note about pointerlike indirections, and remove incorrect destructor note

Closes #2183
Closes #2188
This commit is contained in:
Herb Sutter
2024-04-14 14:34:20 -04:00
parent 4f723b0fff
commit 6c68bf8f34

View File

@@ -3935,7 +3935,7 @@ value) of any assignment operator.
Returning a local variable implicitly moves it anyway.
An explicit `std::move` is always a pessimization, because it prevents Return Value Optimization (RVO),
which can eliminate the move completely.
which can eliminate the move completely.
##### Example, bad
@@ -5096,10 +5096,6 @@ There are two general categories of classes that need a user-defined destructor:
The default destructor does it better, more efficiently, and can't get it wrong.
##### Note
If the default destructor is needed, but its generation has been suppressed (e.g., by defining a move constructor), use `=default`.
##### Enforcement
Look for likely "implicit resources", such as pointers and references. Look for classes with destructors even though all their data members have destructors.
@@ -12682,6 +12678,10 @@ wrong results, or memory corruption.
##### Note
By pointer here we mean any indirection to an object, including equivalently an iterator or view.
##### Note
This rule is an obvious and well-known language rule, but can be hard to follow.
It takes good coding style, library support, and static analysis to eliminate violations without major overhead.
This is a major part of the discussion of [C++'s model for type- and resource-safety](#Stroustrup15).