From: Breuninger Matthias (ETAS-ICA/XPC-Fe3) Date: Tue, 5 Aug 2025 14:38:16 +0000 (+0200) Subject: fix: Error category handling X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=0d627a70c47a8d0cd75839885dd3407384c1fec0;p=thirdparty%2Flldpd.git fix: Error category handling A std::error_code stores the error category only by reference, hence, we must use an object in static storage. Add lldpcli::make_error_code for convenience similar to std::make_error_code. --- diff --git a/src/lib/lldpctl.hpp b/src/lib/lldpctl.hpp index e2e301a7..9d69fdbd 100644 --- a/src/lib/lldpctl.hpp +++ b/src/lib/lldpctl.hpp @@ -64,21 +64,10 @@ /* *** exported interfaces ****************************************************/ -namespace lldpcli { -namespace literals { -/** - * @brief Operator to define std::byte literals. - * - * Example: auto byte{ 0x01_b }; - */ -consteval std::byte operator"" _b(unsigned long long int value) +namespace { - return static_cast(value); -} -} // namespace literals - /** - * @brief LLDP error category. + * @brief LLDP error category. Don't use this class directly, intead, use @ref lldpcli::make_error_code. */ class LldpErrCategory : public std::error_category { public: @@ -90,6 +79,32 @@ class LldpErrCategory : public std::error_category { } }; +const LldpErrCategory lldp_err_category{}; + +} // namespace + +namespace lldpcli { + +/** + * Convenience function to wrap an LLDP error code in a @p std::error_code. + */ +inline std::error_code make_error_code( lldpctl_error_t e ) +{ + return { static_cast( e ), lldp_err_category }; +} + +namespace literals { +/** + * @brief Operator to define std::byte literals. + * + * Example: auto byte{ 0x01_b }; + */ +consteval std::byte operator"" _b(unsigned long long int value) +{ + return static_cast(value); +} +} // namespace literals + /** * @brief Fallback type trait for checking against a const char array. */