diff --git a/src/lib/core/CHIPError.h b/src/lib/core/CHIPError.h index ae1cdf9d63a599..50c4ba994e71b0 100644 --- a/src/lib/core/CHIPError.h +++ b/src/lib/core/CHIPError.h @@ -29,6 +29,7 @@ #pragma once #include +#include #include #include @@ -89,10 +90,7 @@ class ChipError static constexpr bool CanEncapsulate(BaseType value) { return FitsInField(kValueLength, value); } /// Construct a `CHIP_ERROR` encapsulating @a value inside the @a range. - static BaseType Encapsulate(Range range, BaseType value) - { - return MakeInteger(range, (value & MakeMask(kValueStart, kValueLength))); - } + static BaseType Encapsulate(Range range, BaseType value) { return MakeInteger(range, (value & MakeMask(0, kValueLength))); } /// Test whether @a error is an SDK error belonging to @a part. static constexpr bool IsPart(SdkPart part, BaseType error) @@ -133,13 +131,11 @@ class ChipError static constexpr BaseType MakeInteger(Range range, BaseType value) { - return MakeField(kRangeStart, static_cast::type>(range)) | MakeField(kValueStart, value); + return MakeField(kRangeStart, to_underlying(range)) | MakeField(kValueStart, value); } static constexpr BaseType MakeInteger(SdkPart part, BaseType code) { - return MakeInteger(Range::kSDK, - MakeField(kSdkPartStart, static_cast::type>(part)) | - MakeField(kSdkCodeStart, code)); + return MakeInteger(Range::kSDK, MakeField(kSdkPartStart, to_underlying(part)) | MakeField(kSdkCodeStart, code)); } public: @@ -154,7 +150,7 @@ class ChipError template struct MakeSdkErrorConstant { - static_assert(FitsInField(kSdkPartLength, static_cast::type>(part)), "part is too large"); + static_assert(FitsInField(kSdkPartLength, to_underlying(part)), "part is too large"); static_assert(FitsInField(kSdkCodeLength, code), "code is too large"); static_assert(MakeInteger(part, code) != 0, "value is zero"); static constexpr BaseType value = MakeInteger(part, code); diff --git a/src/system/SystemError.cpp b/src/system/SystemError.cpp index 3c6cb006086ed2..82760b6cb7454b 100644 --- a/src/system/SystemError.cpp +++ b/src/system/SystemError.cpp @@ -161,7 +161,7 @@ DLL_EXPORT const char * DescribeErrorLwIP(CHIP_ERROR aError) return nullptr; } - const err_t lError = static_cast(-ChipError::GetValue(aError)); + const err_t lError = static_cast(-static_cast(ChipError::GetValue(aError))); // If we are not compiling with LWIP_DEBUG asserted, the unmapped // local value may go unused.