diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 2771630..14618a0 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -9135,7 +9135,7 @@ Here, we ignore such cases. * [R.31: If you have non-`std` smart pointers, follow the basic pattern from `std`](#Rr-smart) * [R.32: Take a `unique_ptr` parameter to express that a function assumes ownership of a `widget`](#Rr-uniqueptrparam) * [R.33: Take a `unique_ptr&` parameter to express that a function reseats the `widget`](#Rr-reseat) - * [R.34: Take a `shared_ptr` parameter to express that a function is part owner](#Rr-sharedptrparam-owner) + * [R.34: Take a `shared_ptr` parameter to express shared ownership](#Rr-sharedptrparam-owner) * [R.35: Take a `shared_ptr&` parameter to express that a function might reseat the shared pointer](#Rr-sharedptrparam) * [R.36: Take a `const shared_ptr&` parameter to express that it might retain a reference count to the object ???](#Rr-sharedptrparam-const) * [R.37: Do not pass a pointer or reference obtained from an aliased smart pointer](#Rr-smartptrget) @@ -9810,7 +9810,7 @@ Using `unique_ptr` in this way both documents and enforces the function call's r * (Simple) Warn if a function takes a `Unique_pointer` parameter by lvalue reference and does not either assign to it or call `reset()` on it on at least one code path. Suggest taking a `T*` or `T&` instead. * (Simple) ((Foundation)) Warn if a function takes a `Unique_pointer` parameter by reference to `const`. Suggest taking a `const T*` or `const T&` instead. -### R.34: Take a `shared_ptr` parameter to express that a function is part owner +### R.34: Take a `shared_ptr` parameter to express shared ownership ##### Reason @@ -9818,11 +9818,16 @@ This makes the function's ownership sharing explicit. ##### Example, good - void share(shared_ptr); // share -- "will" retain refcount - - void may_share(const shared_ptr&); // "might" retain refcount - - void reseat(shared_ptr&); // "might" reseat ptr + class WidgetUser + { + public: + // WidgetUser will share ownership of the widget + explicit WidgetUser(std::shared_ptr w) noexcept: + m_widget{std::move(w)} {} + // ... + private: + std::shared_ptr m_widget; + }; ##### Enforcement @@ -9842,11 +9847,11 @@ This makes the function's reseating explicit. ##### Example, good - void share(shared_ptr); // share -- "will" retain refcount - - void reseat(shared_ptr&); // "might" reseat ptr - - void may_share(const shared_ptr&); // "might" retain refcount + void ChangeWidget(std::shared_ptr& w) + { + // This will change the callers widget + w = std::make_shared(widget{}); + } ##### Enforcement diff --git a/scripts/hunspell/isocpp.dic b/scripts/hunspell/isocpp.dic index fa60c16..9f9858e 100644 --- a/scripts/hunspell/isocpp.dic +++ b/scripts/hunspell/isocpp.dic @@ -646,6 +646,7 @@ webby Webcolor webcolors WG21 +WidgetUser WorkQueue 'widen' x1