From: Adam C. Emerson Date: Wed, 2 Sep 2020 16:18:22 +0000 (-0400) Subject: common: Make error conversion functions `nodiscard` X-Git-Tag: v16.1.0~1154^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=50c8646a75e922936fc03e5fc97a8edffc60d2d8;p=ceph.git common: Make error conversion functions `nodiscard` As suggested by Casey, so the compiler can catch failures to return errors. Signed-off-by: Adam C. Emerson --- diff --git a/src/common/error_code.cc b/src/common/error_code.cc index c10f98a38f0..60086c550ae 100644 --- a/src/common/error_code.cc +++ b/src/common/error_code.cc @@ -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; diff --git a/src/common/error_code.h b/src/common/error_code.h index 67c6cb448d4..6bcd8cb1791 100644 --- a/src/common/error_code.h +++ b/src/common/error_code.h @@ -71,8 +71,8 @@ inline boost::system::error_condition make_error_condition(errc e) noexcept { return { static_cast(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