Skip to content

Commit

Permalink
Fix issues with gcc-11
Browse files Browse the repository at this point in the history
  • Loading branch information
bialasjaroslaw committed Jul 7, 2023
1 parent a246c0a commit e10f39a
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions result.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ struct ResultValue
new (&_storage) err_t(error.move());
}

void handle_error(const char* str = "") const noexcept(std::is_same<BadAccess, BadAccessNoThrow>::value)
{
// can be if constexpr with c++17 or templated with pre c++17
#if defined(USE_EXCEPTIONS)
if (std::is_same<BadAccess, BadAccessThrow>::value)
throw bad_access(str);
#endif
fprintf(stderr, "%s\n", str);
if (std::is_same<BadAccess, BadAccessNoThrow>::value)
return;
std::terminate();
}

// Add concept for that case, also handle primitive type
template <typename Ret = ok_t, typename Access = access_t,
typename std::enable_if<std::is_same<Access, BadAccessNoThrow>::value, bool>::type = true,
Expand Down Expand Up @@ -265,7 +278,7 @@ struct ResultValue

// What return type? ok_t or const ok_t&
template <typename Ret = const err_t&, typename Access = access_t>
const Ret& error_or(const Ret& ret) const noexcept(noexcept(Err())) // -> Ret
const Ret& error_or(const Ret& ret) const noexcept(/*noexcept(Err())*/true) // -> Ret
{
if (_success || _moved)
return ret;
Expand All @@ -282,18 +295,6 @@ struct ResultValue
return MoveErr();
}

template <typename T = ok_t, typename std::enable_if<std::is_same<T, EmptyValue>::value, T>::type* = nullptr>
void set_success() noexcept(noexcept(set_value({})))
{
set_value({});
}

template <typename T = err_t, typename std::enable_if<std::is_same<T, SimpleError>::value, T>::type* = nullptr>
void set_failure() noexcept(noexcept(set_error({})))
{
set_error({});
}

void set_value(const ok_t& value) noexcept(std::is_nothrow_constructible<ok_t>::value)
{
_moved = false;
Expand All @@ -308,6 +309,18 @@ struct ResultValue
new (&_storage) err_t(error);
}

template <typename T = ok_t, typename std::enable_if<std::is_same<T, EmptyValue>::value, T>::type* = nullptr>
void set_success() noexcept(noexcept(set_value({})))
{
set_value({});
}

template <typename T = err_t, typename std::enable_if<std::is_same<T, SimpleError>::value, T>::type* = nullptr>
void set_failure() noexcept(noexcept(set_error({})))
{
set_error({});
}

explicit operator bool() const noexcept(true)
{
return _success;
Expand Down Expand Up @@ -345,19 +358,6 @@ struct ResultValue
return std::move(*reinterpret_cast<err_t*>(&_storage));
}

void handle_error(const char* str = "") const noexcept(std::is_same<BadAccess, BadAccessNoThrow>::value)
{
// can be if constexpr with c++17 or templated with pre c++17
#if defined(USE_EXCEPTIONS)
if (std::is_same<BadAccess, BadAccessThrow>::value)
throw bad_access(str);
#endif
fprintf(stderr, "%s\n", str);
if (std::is_same<BadAccess, BadAccessNoThrow>::value)
return;
std::terminate();
}

typename std::aligned_storage<_size, _align>::type _storage;
bool _moved = false;
bool _success = false;
Expand Down

0 comments on commit e10f39a

Please sign in to comment.