diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 4d8297cb2..1a4af4b22 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -2978,6 +2978,11 @@ Use the advanced techniques only after demonstrating need, and document that nee For passing sequences of characters see [String](#SS-string). +##### Exception + +To express shared ownership using `shared_ptr` types, rather than following guidelines F.16-21, +instead follow [R.34](#Rr-sharedptrparam-owner), [R.35](#Rr-sharedptrparam), and [R.36](#Rr-sharedptrparam-const). + ### F.16: For "in" parameters, pass cheaply-copied types by value and others by reference to `const` ##### Reason @@ -3029,6 +3034,11 @@ If you need the notion of an optional value, use a pointer, `std::optional`, or * (Simple) ((Foundation)) Warn when a parameter passed by reference to `const` has a size less than `2 * sizeof(void*)`. Suggest passing by value instead. * (Simple) ((Foundation)) Warn when a parameter passed by reference to `const` is `move`d. +##### Exception + +To express shared ownership using `shared_ptr` types, instead follow [R.34](#Rr-sharedptrparam-owner) or [R.36](#Rr-sharedptrparam-const), +depending on whether or not the function unconditionally takes a reference to the argument. + ### F.17: For "in-out" parameters, pass by reference to non-`const` ##### Reason @@ -3107,6 +3117,10 @@ For example: // use p ... possibly std::move(p) onward somewhere else } // p gets destroyed +##### Exception + +If the "will-move-from" parameter is a `shared_ptr` instead follow [R.34](#Rr-sharedptrparam-owner) and pass the `shared_ptr` by value. + ##### Enforcement * Flag all `X&&` parameters (where `X` is not a template type parameter name) where the function body uses them without `std::move`.