]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: Make error conversion functions `nodiscard`
authorAdam C. Emerson <aemerson@redhat.com>
Wed, 2 Sep 2020 16:18:22 +0000 (12:18 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Wed, 9 Sep 2020 02:09:40 +0000 (22:09 -0400)
As suggested by Casey, so the compiler can catch failures to return
errors.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/common/error_code.cc
src/common/error_code.h

index c10f98a38f063d9a1a060f52b2cf374c09c5eb07..60086c550aeb2f42127c551b6fe79ccfad11cafd 100644 (file)
@@ -145,7 +145,7 @@ const error_category& ceph_category() noexcept {
 // This is part of the glue for hooking new code to old. Since
 // Context* and other things give us integer codes from errno, wrap
 // them in an error_code.
-boost::system::error_code to_error_code(int ret) noexcept
+[[nodiscard]] boost::system::error_code to_error_code(int ret) noexcept
 {
   if (ret == 0)
     return {};
@@ -154,7 +154,7 @@ boost::system::error_code to_error_code(int ret) noexcept
 
 // This is more complicated. For the case of categories defined
 // elsewhere, we have to convert everything here.
-int from_error_code(boost::system::error_code e) noexcept
+[[nodiscard]] int from_error_code(boost::system::error_code e) noexcept
 {
   if (!e)
     return 0;
index 67c6cb448d462eb9590df12893339e61f3276388..6bcd8cb1791cdca2aae79ef94639828581e26d03 100644 (file)
@@ -71,8 +71,8 @@ inline boost::system::error_condition make_error_condition(errc e) noexcept {
   return { static_cast<int>(e), ceph_category() };
 }
 
-boost::system::error_code to_error_code(int ret) noexcept;
-int from_error_code(boost::system::error_code e) noexcept;
+[[nodiscard]] boost::system::error_code to_error_code(int ret) noexcept;
+[[nodiscard]] int from_error_code(boost::system::error_code e) noexcept;
 }
 #pragma GCC diagnostic pop
 #pragma clang diagnostic pop