Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Test failing on GCC and Clang #74

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions include/tl/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ using is_copy_assignable_or_void =
template <class T>
using is_move_assignable_or_void =
is_void_or<T, std::is_move_assignable<T>>;


} // namespace detail

Expand Down Expand Up @@ -1225,9 +1225,9 @@ class expected : private detail::expected_move_assign_base<T, E>,
static_assert(!std::is_reference<E>::value, "E must not be a reference");

T *valptr() { return std::addressof(this->m_val); }
const T *valptr() const { return std::addressof(this->m_val); }
const T *valptr() const { return std::addressof(this->m_val); }
unexpected<E> *errptr() { return std::addressof(this->m_unexpect); }
const unexpected<E> *errptr() const { return std::addressof(this->m_unexpect); }
const unexpected<E> *errptr() const { return std::addressof(this->m_unexpect); }

template <class U = T,
detail::enable_if_t<!std::is_void<U>::value> * = nullptr>
Expand Down Expand Up @@ -1525,7 +1525,7 @@ class expected : private detail::expected_move_assign_base<T, E>,
if (rhs.has_value()) {
this->construct(*rhs);
} else {
this->construct_error(rhs.error());
this->construct_error(rhs.error());
}
}

Expand All @@ -1540,8 +1540,8 @@ class expected : private detail::expected_move_assign_base<T, E>,
if (rhs.has_value()) {
this->construct(*rhs);
} else {
this->construct_error(rhs.error());
}
this->construct_error(rhs.error());
}
}

template <
Expand All @@ -1554,8 +1554,8 @@ class expected : private detail::expected_move_assign_base<T, E>,
if (rhs.has_value()) {
this->construct(std::move(*rhs));
} else {
this->construct_error(std::move(rhs.error()));
}
this->construct_error(std::move(rhs.error()));
}
}

template <
Expand All @@ -1568,8 +1568,8 @@ class expected : private detail::expected_move_assign_base<T, E>,
if (rhs.has_value()) {
this->construct(std::move(*rhs));
} else {
this->construct_error(std::move(rhs.error()));
}
this->construct_error(std::move(rhs.error()));
}
}

template <
Expand Down Expand Up @@ -1796,7 +1796,7 @@ class expected : private detail::expected_move_assign_base<T, E>,
void swap_where_only_one_has_value_and_t_is_not_void(
expected &rhs, t_is_nothrow_move_constructible,
move_constructing_e_can_throw) {
auto temp = std::move(val());
auto temp(std::move(val()));
val().~T();
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
try {
Expand All @@ -1805,7 +1805,7 @@ class expected : private detail::expected_move_assign_base<T, E>,
::new (rhs.valptr()) T(std::move(temp));
std::swap(this->m_has_val, rhs.m_has_val);
} catch (...) {
val() = std::move(temp);
new (valptr()) T(std::move(temp));
throw;
}
#else
Expand Down Expand Up @@ -1991,7 +1991,7 @@ constexpr auto and_then_impl(Exp &&exp, F &&f) -> Ret {

#ifdef TL_EXPECTED_CXX14
template <class Exp, class F,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
*std::declval<Exp>())),
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2003,7 +2003,7 @@ constexpr auto expected_map_impl(Exp &&exp, F &&f) {
}

template <class Exp, class F,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
*std::declval<Exp>())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2028,7 +2028,7 @@ constexpr auto expected_map_impl(Exp &&exp, F &&f) {
}

template <class Exp, class F,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
auto expected_map_impl(Exp &&exp, F &&f) {
Expand All @@ -2039,10 +2039,10 @@ auto expected_map_impl(Exp &&exp, F &&f) {
}

return result(unexpect, std::forward<Exp>(exp).error());
}
}
#else
template <class Exp, class F,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
*std::declval<Exp>())),
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2057,7 +2057,7 @@ constexpr auto expected_map_impl(Exp &&exp, F &&f)
}

template <class Exp, class F,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
*std::declval<Exp>())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2072,7 +2072,7 @@ auto expected_map_impl(Exp &&exp, F &&f) -> expected<void, err_t<Exp>> {
}

template <class Exp, class F,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>())),
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>

Expand All @@ -2085,7 +2085,7 @@ constexpr auto expected_map_impl(Exp &&exp, F &&f)
}

template <class Exp, class F,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>

Expand All @@ -2096,13 +2096,13 @@ auto expected_map_impl(Exp &&exp, F &&f) -> expected<void, err_t<Exp>> {
}

return unexpected<err_t<Exp>>(std::forward<Exp>(exp).error());
}
}
#endif

#if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \
!defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55)
template <class Exp, class F,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
std::declval<Exp>().error())),
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2114,7 +2114,7 @@ constexpr auto map_error_impl(Exp &&exp, F &&f) {
std::forward<Exp>(exp).error()));
}
template <class Exp, class F,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
std::declval<Exp>().error())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2128,7 +2128,7 @@ auto map_error_impl(Exp &&exp, F &&f) {
return result(unexpect, monostate{});
}
template <class Exp, class F,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
std::declval<Exp>().error())),
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2140,7 +2140,7 @@ constexpr auto map_error_impl(Exp &&exp, F &&f) {
std::forward<Exp>(exp).error()));
}
template <class Exp, class F,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
std::declval<Exp>().error())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2152,10 +2152,10 @@ auto map_error_impl(Exp &&exp, F &&f) {

detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
return result(unexpect, monostate{});
}
}
#else
template <class Exp, class F,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
std::declval<Exp>().error())),
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2170,7 +2170,7 @@ constexpr auto map_error_impl(Exp &&exp, F &&f)
}

template <class Exp, class F,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<!std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
std::declval<Exp>().error())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2185,7 +2185,7 @@ auto map_error_impl(Exp &&exp, F &&f) -> expected<exp_t<Exp>, monostate> {
}

template <class Exp, class F,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
std::declval<Exp>().error())),
detail::enable_if_t<!std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2200,7 +2200,7 @@ constexpr auto map_error_impl(Exp &&exp, F &&f)
}

template <class Exp, class F,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
detail::enable_if_t<std::is_void<exp_t<Exp>>::value> * = nullptr,
class Ret = decltype(detail::invoke(std::declval<F>(),
std::declval<Exp>().error())),
detail::enable_if_t<std::is_void<Ret>::value> * = nullptr>
Expand All @@ -2212,7 +2212,7 @@ auto map_error_impl(Exp &&exp, F &&f) -> expected<exp_t<Exp>, monostate> {

detail::invoke(std::forward<F>(f), std::forward<Exp>(exp).error());
return result(unexpect, monostate{});
}
}
#endif

#ifdef TL_EXPECTED_CXX14
Expand Down
2 changes: 0 additions & 2 deletions tests/swap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ TEST_CASE("swap") {
tl::expected<no_throw, willthrow_move> b{tl::unexpect, s2};
should_throw = 1;

#ifdef _MSC_VER
//this seems to break catch on GCC and Clang
REQUIRE_THROWS(swap(a, b));
#endif

REQUIRE(a->i == s1);
REQUIRE(b.error().i == s2);
Expand Down
19 changes: 16 additions & 3 deletions tests/test.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "../include/tl/expected.hpp"
#include <string>


struct no_throw {
no_throw(std::string i) : i(i) {}
std::string i;
Expand Down Expand Up @@ -27,6 +31,15 @@ int main() {
std::string s2 = "zyxwvutsrqponmlkjihgfedcbaxxx";
tl::expected<no_throw, willthrow_move> a{s1};
tl::expected<no_throw, willthrow_move> b{tl::unexpect, s2};
should_throw = 1;
swap(a, b);
}
should_throw = true;
bool has_thrown = false;
try {
swap(a, b);
} catch (...) {
has_thrown = true;
}
if(should_throw == has_thrown){
return 0;
}
return 1;
}