Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exceptions to F.15, F.16, and F.18 for shared_ptr types #2010

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CppCoreGuidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

### <a name="Rf-in"></a>F.16: For "in" parameters, pass cheaply-copied types by value and others by reference to `const`

##### Reason
Expand Down Expand Up @@ -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.

### <a name="Rf-inout"></a>F.17: For "in-out" parameters, pass by reference to non-`const`

##### Reason
Expand Down Expand Up @@ -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`.
Expand Down