Resource management
R.20
Use `unique_ptr` or `shared_ptr` to represent ownership
Reason
They can prevent resource leaks.
Example
Consider:
void f()
{
X* p1 { new X }; // bad, p1 will leak
auto p2 = make_unique<X>(); // good, unique ownership
auto p3 = make_shared<X>(); // good, shared ownership
}
This will leak the object used to initialize p1 (only).
Enforcement
- (Simple) Warn if the return value of
newis assigned to a raw pointer. - (Simple) Warn if the result of a function returning a raw owning pointer is assigned to a raw pointer.