Wrap try-catch blocks for -fno-exceptions

This commit is contained in:
Simon Brand
2019-05-02 09:16:31 +01:00
parent 2c9780949d
commit aa22af4d9d

View File

@ -719,12 +719,16 @@ struct expected_operations_base : expected_storage_base<T, E> {
auto tmp = std::move(geterr());
geterr().~unexpected<E>();
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
try {
construct(rhs.get());
} catch (...) {
geterr() = std::move(tmp);
throw;
}
#else
construct(rhs.get());
#endif
} else {
assign_common(rhs);
}
@ -750,12 +754,16 @@ struct expected_operations_base : expected_storage_base<T, E> {
if (!this->m_has_val && rhs.m_has_val) {
auto tmp = std::move(geterr());
geterr().~unexpected<E>();
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
try {
construct(std::move(rhs).get());
} catch (...) {
geterr() = std::move(tmp);
throw;
}
#else
construct(std::move(rhs).get());
#endif
} else {
assign_common(std::move(rhs));
}
@ -1879,6 +1887,7 @@ private:
move_constructing_e_can_throw) {
auto temp = std::move(val());
val().~T();
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
try {
::new (errptr()) unexpected_type(std::move(rhs.err()));
rhs.err().~unexpected_type();
@ -1888,6 +1897,12 @@ private:
val() = std::move(temp);
throw;
}
#else
::new (errptr()) unexpected_type(std::move(rhs.err()));
rhs.err().~unexpected_type();
::new (rhs.valptr()) T(std::move(temp));
std::swap(this->m_has_val, rhs.m_has_val);
#endif
}
void swap_where_only_one_has_value_and_t_is_not_void(
@ -1895,6 +1910,7 @@ private:
t_is_nothrow_move_constructible) {
auto temp = std::move(rhs.err());
rhs.err().~unexpected_type();
#ifdef TL_EXPECTED_EXCEPTIONS_ENABLED
try {
::new (rhs.valptr()) T(val());
val().~T();
@ -1904,6 +1920,12 @@ private:
rhs.err() = std::move(temp);
throw;
}
#else
::new (rhs.valptr()) T(val());
val().~T();
::new (errptr()) unexpected_type(std::move(temp));
std::swap(this->m_has_val, rhs.m_has_val);
#endif
}
public: