Resource management
R.22
Use `make_shared()` to make `shared_ptr`s
Reason
make_shared gives a more concise statement of the construction. It also gives an opportunity to eliminate a separate allocation for the reference counts, by placing the shared_ptr's use counts next to its object. It also ensures exception safety in complex expressions (in pre-C++17 code).
Example
Consider:
shared_ptr<X> p1 { new X{2} }; // bad
auto p = make_shared<X>(2); // good
The make_shared() version mentions X only once, so it is usually shorter (as well as faster) than the version with the explicit new.
Enforcement
(Simple) Warn if a shared_ptr is constructed from the result of new rather than make_shared.