From 104cd63a377f16f7031513e1384e39c4bba63d1b Mon Sep 17 00:00:00 2001 From: hsutter Date: Thu, 6 Sep 2018 11:59:34 -0700 Subject: [PATCH] Closes #1257 Fixed example --- CppCoreGuidelines.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 513d8d0..70201fb 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -15798,7 +15798,7 @@ This can be messy: } Simulating RAII can be non-trivial, especially in functions with multiple resources and multiple possible errors. -A not uncommon technique is to gather cleanup at the end of the function to avoid repetition: +A not uncommon technique is to gather cleanup at the end of the function to avoid repetition (note the extra scope around `g2` is undesirable but necessary to make the `goto` version compile): std::pair user() { @@ -15810,6 +15810,7 @@ A not uncommon technique is to gather cleanup at the end of the function to avoi goto exit; } + { Gadget g2 = make_gadget(17); if (!g2.valid()) { err = g2_error; @@ -15821,6 +15822,7 @@ A not uncommon technique is to gather cleanup at the end of the function to avoi goto exit; } // ... + } exit: if (g1.valid()) cleanup(g1);