Resource management
R.35
Take a `shared_ptr<widget>&` parameter to express that a function might reseat the shared pointer
Reason
This makes the function's reseating explicit.
Note
"reseat" means "making a reference or a smart pointer refer to a different object."
Example, good
void ChangeWidget(std::shared_ptr<widget>& w)
{
// This will change the callers widget
w = std::make_shared<widget>(widget{});
}
Enforcement
- (Simple) Warn if a function takes a
Shared_pointer<T>parameter by lvalue reference and does not either assign to it or callreset()on it on at least one code path. Suggest taking aT*orT&instead. - (Simple) ((Foundation)) Warn if a function takes a
Shared_pointer<T>by value or by reference toconstand does not copy or move it to anotherShared_pointeron at least one code path. Suggest taking aT*orT&instead. - (Simple) ((Foundation)) Warn if a function takes a
Shared_pointer<T>by rvalue reference. Suggesting taking it by value instead.