From 6c68bf8f343d4996fbe456b0a5281526c1b9e6c5 Mon Sep 17 00:00:00 2001 From: Herb Sutter Date: Sun, 14 Apr 2024 14:34:20 -0400 Subject: [PATCH] Add note about pointerlike indirections, and remove incorrect destructor note Closes #2183 Closes #2188 --- CppCoreGuidelines.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index b68e6d0..ab07764 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -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).