Skip to content

Commit

Permalink
lowlevel: Add explicit default ctor for ResultStorage on VS 2019
Browse files Browse the repository at this point in the history
For some reason simply making the val_or_err field a
default-constructible type wasn't enough to work around the bug.
This commit also makes the compiler check more specific, as the
bug was present until partway through the VS 17.2 release cycle.
  • Loading branch information
caseif committed Jun 13, 2024
1 parent 341900f commit 1da23ad
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions engine/libs/lowlevel/include/argus/lowlevel/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ namespace argus {

template<typename T, typename E>
struct ResultStorage {
#if defined(_MSC_VER) && _MSC_VER < 1930
// workaround for VS 2019 and earlier which requires std::future's type
// parameter type to be default-constructible
#if defined(_MSC_VER) && (_MSVC_STL_UPDATE < 202203L)
// workaround for VS versions prior to 17.2 (2022) which require
// std::future's type parameter type to be default-constructible
std::optional<std::variant<reference_wrapped_t<T>, reference_wrapped_t<E>>> val_or_err;

ResultStorage(void) = default;
#else
std::variant<reference_wrapped_t<T>, reference_wrapped_t<E>> val_or_err;
#endif
Expand Down Expand Up @@ -88,8 +90,8 @@ namespace argus {

[[nodiscard]] bool is_ok(void) const {
if constexpr (!std::is_void_v<T> && !std::is_void_v<E>) {
#if defined _MSC_VER && _MSC_VER < 1930
// workaround for VS <=2019, see comment in ResultStorage
#if defined _MSC_VER && _MSC_VER < 1932
// workaround for VS <=17.2, see comment in ResultStorage
// definition
return m_storage.val_or_err.value().index() == 0;
#else
Expand All @@ -114,8 +116,8 @@ namespace argus {
crash_ll("Attempted to call unwrap() on error-typed Result");
}
if constexpr (!std::is_void_v<E>) {
#if defined(_MSC_VER) && _MSC_VER < 1930
// workaround for VS <=2019, see comment in ResultStorage
#if defined(_MSC_VER) && (_MSVC_STL_UPDATE < 202203L)
// workaround for VS <=17.2, see comment in ResultStorage
// definition
return std::get<0>(m_storage.val_or_err.value());
#else
Expand All @@ -137,8 +139,8 @@ namespace argus {
crash_ll("Attempted to call unwrap() on value-typed Result");
}
if constexpr (!std::is_void_v<T>) {
#if defined(_MSC_VER) && _MSC_VER < 1930
// workaround for VS <=2019, see comment in ResultStorage
#if defined(_MSC_VER) && (_MSVC_STL_UPDATE < 202203L)
// workaround for VS <=17.2, see comment in ResultStorage
// definition
return std::get<1>(m_storage.val_or_err.value());
#else
Expand Down Expand Up @@ -264,8 +266,9 @@ namespace argus {
static_assert(!std::is_void_v<T>);

if constexpr (!std::is_void_v<E>) {
#if defined(_MSC_VER) && _MSC_VER < 1930
// workaround for VS <=2019, see comment in ResultStorage definition
#if defined(_MSC_VER) && (_MSVC_STL_UPDATE < 202203L)
// workaround for VS <=17.2, see comment in ResultStorage
// definition
return Result<T, E>(ResultStorage<T, E> { std::make_optional(
std::variant<reference_wrapped_t<T>, reference_wrapped_t<E>> {
std::in_place_index<0>, wrap_if_reference<T>(value)
Expand Down

0 comments on commit 1da23ad

Please sign in to comment.