From 0b1b5bbac85f765c072ef766693221b5c1267145 Mon Sep 17 00:00:00 2001 From: Vincas Dargis Date: Sat, 1 Jul 2017 19:29:35 +0300 Subject: [PATCH] Fix if statement for checking error condition Example mentions that it handles error, and errors are commonly non-zero values. Closes #970 --- CppCoreGuidelines.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 8172464..ae4204f 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -1738,7 +1738,7 @@ If you can't use exceptions (e.g. because your code is full of old-style raw-poi int val; int error_code; tie(val, error_code) = do_something(); - if (error_code == 0) { + if (error_code) { // ... handle the error or exit ... } // ... use val ... @@ -1747,7 +1747,7 @@ This style unfortunately leads to uninitialized variables. A facility [structured bindings](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0144r1.pdf) to deal with that will become available in C++17. auto [val, error_code] = do_something(); - if (error_code == 0) { + if (error_code) { // ... handle the error or exit ... } // ... use val ...