diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 8d5945f..1de6112 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -9788,19 +9788,17 @@ Consider: void f() { - X x; - X* p1 { new X }; // see also ??? - unique_ptr p2 { new X }; // unique ownership; see also ??? - shared_ptr p3 { new X }; // shared ownership; see also ??? - auto p4 = make_unique(); // unique_ownership, preferable to the explicit use "new" - auto p5 = make_shared(); // shared ownership, preferable to the explicit use "new" + X* p1 { new X }; // bad, p1 will leak + auto p2 = make_unique(); // good, unique ownership + auto p3 = make_shared(); // good, shared ownership } This will leak the object used to initialize `p1` (only). ##### Enforcement -(Simple) Warn if the return value of `new` or a function call with return value of pointer type is assigned to a raw pointer. +* (Simple) Warn if the return value of `new` is assigned to a raw pointer. +* (Simple) Warn if the result of a function returning a raw owning pointer is assigned to a raw pointer. ### R.21: Prefer `unique_ptr` over `shared_ptr` unless you need to share ownership