From bf29c350823e72c5975aa592921ca033f988331d Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Wed, 19 Oct 2022 20:29:43 +0200 Subject: [PATCH] ES.24 (Use a unique_ptr) Example should `delete` the raw pointer (#1986) Without having a `delete p2` statement at the end, the claim that "the object pointed to by `p2` is leaked" would just seem trivial. --- CppCoreGuidelines.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 0af7ad6..9af57c9 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -11140,11 +11140,12 @@ increases readability, and it has zero or near zero run-time cost. // ... no assignment to p2 ... vector v(7); v.at(7) = 0; // exception thrown + delete p2; // too late to prevent leaks // ... } If `leak == true` the object pointed to by `p2` is leaked and the object pointed to by `p1` is not. -The same is the case when `at()` throws. +The same is the case when `at()` throws. In both cases, the `delete p2` statement is not reached. ##### Enforcement