From 50c8646a75e922936fc03e5fc97a8edffc60d2d8 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Wed, 2 Sep 2020 12:18:22 -0400 Subject: [PATCH] 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 --- src/common/error_code.cc | 4 ++-- src/common/error_code.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/error_code.cc b/src/common/error_code.cc index c10f98a38f063..60086c550aeb2 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 67c6cb448d462..6bcd8cb1791cd 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 -- 2.39.5