ams: mark ams::Result [[nodiscard]] (partially complete).
NOTE: This work is not yet fully complete; kernel is done, but it was taking an exceedingly long time to get through libstratosphere. Thus, I've temporarily added -Wno-error=unused-result for libstratosphere/stratosphere. All warnings should be fixed to do the same thing Nintendo does as relevant, but this is taking a phenomenally long time and is not actually the most important work to do, so it can be put off for some time to prioritize other tasks for 21.0.0 support.
This commit is contained in:
@@ -53,7 +53,7 @@ namespace ams {
|
||||
return (v >> ofs) & ~(~BaseType() << num);
|
||||
}
|
||||
public:
|
||||
static constexpr ALWAYS_INLINE BaseType MakeValue(BaseType module, BaseType description) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType MakeValue(BaseType module, BaseType description) {
|
||||
return (module) | (description << ModuleBits);
|
||||
}
|
||||
|
||||
@@ -63,23 +63,23 @@ namespace ams {
|
||||
static_assert(description < (1 << DescriptionBits), "Invalid Description");
|
||||
};
|
||||
|
||||
static constexpr ALWAYS_INLINE BaseType GetModuleFromValue(BaseType value) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType GetModuleFromValue(BaseType value) {
|
||||
return GetBitsValue(value, 0, ModuleBits);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE BaseType GetDescriptionFromValue(BaseType value) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType GetDescriptionFromValue(BaseType value) {
|
||||
return GetBitsValue(value, ModuleBits, DescriptionBits);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE BaseType GetReservedFromValue(BaseType value) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType GetReservedFromValue(BaseType value) {
|
||||
return GetBitsValue(value, ModuleBits + DescriptionBits, ReservedBits);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE BaseType MaskReservedFromValue(BaseType value) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType MaskReservedFromValue(BaseType value) {
|
||||
return value & ~(~(~BaseType() << ReservedBits) << (ModuleBits + DescriptionBits));
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE BaseType MergeValueWithReserved(BaseType value, BaseType reserved) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType MergeValueWithReserved(BaseType value, BaseType reserved) {
|
||||
return (value << 0) | (reserved << (ModuleBits + DescriptionBits));
|
||||
}
|
||||
};
|
||||
@@ -90,8 +90,8 @@ namespace ams {
|
||||
using BaseType = typename ResultTraits::BaseType;
|
||||
static constexpr BaseType SuccessValue = ResultTraits::SuccessValue;
|
||||
public:
|
||||
constexpr ALWAYS_INLINE BaseType GetModule(this auto const &self) { return ResultTraits::GetModuleFromValue(self.GetValue()); }
|
||||
constexpr ALWAYS_INLINE BaseType GetDescription(this auto const &self) { return ResultTraits::GetDescriptionFromValue(self.GetValue()); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE BaseType GetModule(this auto const &self) { return ResultTraits::GetModuleFromValue(self.GetValue()); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE BaseType GetDescription(this auto const &self) { return ResultTraits::GetDescriptionFromValue(self.GetValue()); }
|
||||
};
|
||||
|
||||
class ResultInternalAccessor;
|
||||
@@ -100,7 +100,7 @@ namespace ams {
|
||||
|
||||
class ResultSuccess;
|
||||
|
||||
class Result final : public result::impl::ResultBase {
|
||||
class [[nodiscard]] Result final : public result::impl::ResultBase {
|
||||
friend class result::impl::ResultInternalAccessor;
|
||||
public:
|
||||
using Base = typename result::impl::ResultBase;
|
||||
@@ -115,16 +115,17 @@ namespace ams {
|
||||
constexpr ALWAYS_INLINE Result(typename Base::BaseType v) : m_value(v) { static_assert(std::is_same<typename Base::BaseType, ::Result>::value); }
|
||||
|
||||
constexpr ALWAYS_INLINE operator ResultSuccess() const;
|
||||
static constexpr ALWAYS_INLINE bool CanAccept(Result) { return true; }
|
||||
|
||||
constexpr ALWAYS_INLINE bool IsSuccess() const { return m_value == Base::SuccessValue; }
|
||||
constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetModule() const { return Base::GetModule(); }
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetDescription() const { return Base::GetDescription(); }
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE bool CanAccept(Result) { return true; }
|
||||
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetInnerValue() const { return ::ams::result::impl::ResultTraits::MaskReservedFromValue(m_value); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsSuccess() const { return m_value == Base::SuccessValue; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetModule() const { return Base::GetModule(); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetDescription() const { return Base::GetDescription(); }
|
||||
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return m_value; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetInnerValue() const { return ::ams::result::impl::ResultTraits::MaskReservedFromValue(m_value); }
|
||||
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return m_value; }
|
||||
};
|
||||
static_assert(sizeof(Result) == sizeof(Result::Base::BaseType), "sizeof(Result) == sizeof(Result::Base::BaseType)");
|
||||
static_assert(std::is_trivially_destructible<Result>::value, "std::is_trivially_destructible<Result>::value");
|
||||
@@ -137,20 +138,20 @@ namespace ams {
|
||||
|
||||
class ResultInternalAccessor {
|
||||
public:
|
||||
static constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) {
|
||||
return Result(value);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE ResultTraits::BaseType GetReserved(Result result) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE ResultTraits::BaseType GetReserved(Result result) {
|
||||
return ResultTraits::GetReservedFromValue(result.m_value);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE Result MergeReserved(Result result, ResultTraits::BaseType reserved) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE Result MergeReserved(Result result, ResultTraits::BaseType reserved) {
|
||||
return Result(ResultTraits::MergeValueWithReserved(ResultTraits::MaskReservedFromValue(result.m_value), reserved));
|
||||
}
|
||||
};
|
||||
|
||||
constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) {
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) {
|
||||
return ResultInternalAccessor::MakeResult(value);
|
||||
}
|
||||
|
||||
@@ -161,12 +162,12 @@ namespace ams {
|
||||
using Base = typename result::impl::ResultBase;
|
||||
public:
|
||||
constexpr ALWAYS_INLINE operator Result() const { return result::impl::MakeResult(Base::SuccessValue); }
|
||||
static constexpr ALWAYS_INLINE bool CanAccept(Result result) { return result.IsSuccess(); }
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE bool CanAccept(Result result) { return result.IsSuccess(); }
|
||||
|
||||
constexpr ALWAYS_INLINE bool IsSuccess() const { return true; }
|
||||
constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsSuccess() const { return true; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Base::SuccessValue; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Base::SuccessValue; }
|
||||
};
|
||||
|
||||
namespace result::impl {
|
||||
@@ -203,10 +204,10 @@ namespace ams {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE bool IsSuccess() const { return false; }
|
||||
constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsSuccess() const { return false; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Value; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Value; }
|
||||
};
|
||||
|
||||
template<ResultTraits::BaseType _Module, ResultTraits::BaseType DescStart, ResultTraits::BaseType DescEnd>
|
||||
@@ -223,7 +224,7 @@ namespace ams {
|
||||
static constexpr typename ResultTraits::BaseType StartValue = ResultTraits::MakeStaticValue<Module, DescriptionStart>::value;
|
||||
static constexpr typename ResultTraits::BaseType EndValue = ResultTraits::MakeStaticValue<Module, DescriptionEnd>::value;
|
||||
public:
|
||||
static constexpr ALWAYS_INLINE bool Includes(Result result) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE bool Includes(Result result) {
|
||||
if constexpr (UseDirectValueComparison) {
|
||||
const auto inner_value = result.GetInnerValue();
|
||||
if constexpr (StartValue == EndValue) {
|
||||
|
||||
Reference in New Issue
Block a user