E.27: make example compile, closes #1622

This commit is contained in:
Sergey Zubkov 2020-08-03 16:48:37 -04:00
parent 0439326363
commit 2449d5d60f

View File

@ -1,6 +1,6 @@
# <a name="main"></a>C++ Core Guidelines # <a name="main"></a>C++ Core Guidelines
July 3, 2020 August 3, 2020
Editors: Editors:
@ -16190,7 +16190,7 @@ This can be messy:
return {0, g1_error}; return {0, g1_error};
} }
Gadget g2 = make_gadget(17); Gadget g2 = make_gadget(31);
if (!g2.valid()) { if (!g2.valid()) {
cleanup(g1); cleanup(g1);
return {0, g2_error}; return {0, g2_error};
@ -16199,13 +16199,15 @@ This can be messy:
// ... // ...
if (all_foobar(g1, g2)) { if (all_foobar(g1, g2)) {
cleanup(g1);
cleanup(g2); cleanup(g2);
cleanup(g1);
return {0, foobar_error}; return {0, foobar_error};
}
// ... // ...
cleanup(g1);
cleanup(g2); cleanup(g2);
cleanup(g1);
return {res, 0}; return {res, 0};
} }
@ -16215,30 +16217,34 @@ A not uncommon technique is to gather cleanup at the end of the function to avoi
std::pair<int, error_indicator> user() std::pair<int, error_indicator> user()
{ {
error_indicator err = 0; error_indicator err = 0;
int res = 0;
Gadget g1 = make_gadget(17); Gadget g1 = make_gadget(17);
if (!g1.valid()) { if (!g1.valid()) {
err = g1_error; err = g1_error;
goto exit; goto g1_exit;
} }
{ {
Gadget g2 = make_gadget(17); Gadget g2 = make_gadget(31);
if (!g2.valid()) { if (!g2.valid()) {
err = g2_error; err = g2_error;
goto exit; goto g2_exit;
} }
if (all_foobar(g1, g2)) { if (all_foobar(g1, g2)) {
err = foobar_error; err = foobar_error;
goto exit; goto g2_exit;
}
// ...
} }
exit: // ...
if (g1.valid()) cleanup(g1);
g2_exit:
if (g2.valid()) cleanup(g2); if (g2.valid()) cleanup(g2);
}
g1_exit:
if (g1.valid()) cleanup(g1);
return {res, err}; return {res, err};
} }