mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 01:10:28 +03:00
AK: Disallow implicitly copying Error and ErrorOr instances
In the rare cases that a copy is actually needed, the Error::copy factory will suffice.
This commit is contained in:
parent
604d5f5bca
commit
8eb3d79129
Notes:
sideshowbarker
2024-07-18 00:54:03 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/8eb3d79129 Pull-request: https://github.com/SerenityOS/serenity/pull/17399 Reviewed-by: https://github.com/linusg
23
AK/Error.h
23
AK/Error.h
@ -21,6 +21,9 @@ namespace AK {
|
||||
|
||||
class Error {
|
||||
public:
|
||||
ALWAYS_INLINE Error(Error&&) = default;
|
||||
ALWAYS_INLINE Error& operator=(Error&&) = default;
|
||||
|
||||
[[nodiscard]] static Error from_errno(int code) { return Error(code); }
|
||||
[[nodiscard]] static Error from_syscall(StringView syscall_name, int rc) { return Error(syscall_name, rc); }
|
||||
[[nodiscard]] static Error from_string_view(StringView string_literal) { return Error(string_literal); }
|
||||
@ -79,6 +82,9 @@ private:
|
||||
{
|
||||
}
|
||||
|
||||
Error(Error const&) = default;
|
||||
Error& operator=(Error const&) = default;
|
||||
|
||||
StringView m_string_literal;
|
||||
int m_code { 0 };
|
||||
bool m_syscall { false };
|
||||
@ -100,23 +106,10 @@ public:
|
||||
}
|
||||
|
||||
ALWAYS_INLINE ErrorOr(ErrorOr&&) = default;
|
||||
ALWAYS_INLINE ErrorOr(ErrorOr const&) = default;
|
||||
ALWAYS_INLINE ErrorOr& operator=(ErrorOr&&) = default;
|
||||
ALWAYS_INLINE ErrorOr& operator=(ErrorOr const&) = default;
|
||||
|
||||
template<typename U>
|
||||
ALWAYS_INLINE ErrorOr(ErrorOr<U, ErrorType> const& value)
|
||||
requires(IsConvertible<U, T>)
|
||||
: m_value_or_error(value.m_value_or_error.visit([](U const& v) -> Variant<T, ErrorType> { return v; }, [](ErrorType const& error) -> Variant<T, ErrorType> { return error; }))
|
||||
{
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
ALWAYS_INLINE ErrorOr(ErrorOr<U, ErrorType>& value)
|
||||
requires(IsConvertible<U, T>)
|
||||
: m_value_or_error(value.m_value_or_error.visit([](U& v) { return Variant<T, ErrorType>(move(v)); }, [](ErrorType& error) { return Variant<T, ErrorType>(move(error)); }))
|
||||
{
|
||||
}
|
||||
ErrorOr(ErrorOr const&) = delete;
|
||||
ErrorOr& operator=(ErrorOr const&) = delete;
|
||||
|
||||
template<typename U>
|
||||
ALWAYS_INLINE ErrorOr(ErrorOr<U, ErrorType>&& value)
|
||||
|
Loading…
Reference in New Issue
Block a user