From feb0eb930971c49f2e9626435aa44ea0a01300a1 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 28 Dec 2022 20:12:03 +0000 Subject: [PATCH] AK: Fix constructing ErrorOr from ErrorOr of a related type Mark other ErrorOr types as friends, and fix a typo in the && constructor, so that we can create an ErrorOr from an ErrorOr. Also, add some requires() clauses to these constructors so the error messages are clearer. --- AK/Error.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AK/Error.h b/AK/Error.h index 50185897f5b..fa6e4e4ae6d 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -81,6 +81,9 @@ private: template class [[nodiscard]] ErrorOr { + template + friend class ErrorOr; + public: using ResultType = T; using ErrorType = E; @@ -98,19 +101,22 @@ public: template ALWAYS_INLINE ErrorOr(ErrorOr const& value) + requires(IsConvertible) : m_value_or_error(value.m_value_or_error.visit([](U const& v) -> Variant { return v; }, [](ErrorType const& error) -> Variant { return error; })) { } template ALWAYS_INLINE ErrorOr(ErrorOr& value) + requires(IsConvertible) : m_value_or_error(value.m_value_or_error.visit([](U& v) { return Variant(move(v)); }, [](ErrorType& error) { return Variant(move(error)); })) { } template ALWAYS_INLINE ErrorOr(ErrorOr&& value) - : m_value_or_error(value.visit([](U& v) { return Variant(move(v)); }, [](ErrorType& error) { return Variant(move(error)); })) + requires(IsConvertible) + : m_value_or_error(value.m_value_or_error.visit([](U& v) { return Variant(move(v)); }, [](ErrorType& error) { return Variant(move(error)); })) { }