diff --git a/AK/Function.h b/AK/Function.h index e553bd5e86..a5bc0489f7 100644 --- a/AK/Function.h +++ b/AK/Function.h @@ -62,13 +62,13 @@ public: } template - Function(CallableType&& callable) requires((IsFunctionObject && IsCallableWithArguments)) + Function(CallableType&& callable) requires((IsFunctionObject && IsCallableWithArguments && !IsSame, Function>)) { init_with_callable(forward(callable)); } template - Function(FunctionType f) requires((IsFunctionPointer && IsCallableWithArguments, In...>)) + Function(FunctionType f) requires((IsFunctionPointer && IsCallableWithArguments, In...> && !IsSame, Function>)) { init_with_callable(move(f)); } diff --git a/Kernel/KResult.h b/Kernel/KResult.h index 793d65438e..05ae90ba25 100644 --- a/Kernel/KResult.h +++ b/Kernel/KResult.h @@ -58,24 +58,30 @@ public: } ALWAYS_INLINE KResultOr(T&& value) + : m_have_storage(true) { new (&m_storage) T(move(value)); - m_have_storage = true; + } + + ALWAYS_INLINE KResultOr(const T& value) + : m_have_storage(true) + { + new (&m_storage) T(value); } template - ALWAYS_INLINE KResultOr(U&& value) + ALWAYS_INLINE KResultOr(U&& value) requires(!IsSame, KResultOr>) + : m_have_storage(true) { - new (&m_storage) T(move(value)); - m_have_storage = true; + new (&m_storage) T(forward(value)); } KResultOr(KResultOr&& other) { m_is_error = other.m_is_error; - if (m_is_error) + if (m_is_error) { m_error = other.m_error; - else { + } else { if (other.m_have_storage) { new (&m_storage) T(move(other.value())); m_have_storage = true; @@ -96,9 +102,9 @@ public: m_have_storage = false; } m_is_error = other.m_is_error; - if (m_is_error) + if (m_is_error) { m_error = other.m_error; - else { + } else { if (other.m_have_storage) { new (&m_storage) T(move(other.value())); m_have_storage = true;