From: jacobly0 Date: Sun, 8 May 2022 14:12:28 +0000 (+0200) Subject: fix: Fix miscompile of nonstd::expected on MSVC v19.22 (#1053) X-Git-Tag: v4.6.1~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e97a52820f34c4be8e628eea76885b1ded71518b;p=thirdparty%2Fccache.git fix: Fix miscompile of nonstd::expected on MSVC v19.22 (#1053) --- diff --git a/src/third_party/nonstd/expected.hpp b/src/third_party/nonstd/expected.hpp index 69bee7506..2bd18344a 100644 --- a/src/third_party/nonstd/expected.hpp +++ b/src/third_party/nonstd/expected.hpp @@ -1,6 +1,6 @@ // This version targets C++11 and later. // -// Copyright (C) 2016-2018 Martin Moene. +// Copyright (C) 2016-2020 Martin Moene. // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -66,16 +66,25 @@ # define nsel_P0323R 7 #endif -// Control presence of exception handling (try and auto discover): +// Control presence of C++ exception handling (try and auto discover): #ifndef nsel_CONFIG_NO_EXCEPTIONS -# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND) +# if defined(_MSC_VER) +# include // for _HAS_EXCEPTIONS +# endif +# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || (_HAS_EXCEPTIONS) # define nsel_CONFIG_NO_EXCEPTIONS 0 # else # define nsel_CONFIG_NO_EXCEPTIONS 1 # endif #endif +// at default use SEH with MSVC for no C++ exceptions + +#ifndef nsel_CONFIG_NO_EXCEPTIONS_SEH +# define nsel_CONFIG_NO_EXCEPTIONS_SEH ( nsel_CONFIG_NO_EXCEPTIONS && _MSC_VER ) +#endif + // C++ language version detection (C++20 is speculative): // Note: VC14.0/1900 (VS2015) lacks too much from C++14. @@ -224,7 +233,11 @@ namespace nonstd { // additional includes: #if nsel_CONFIG_NO_EXCEPTIONS +# if nsel_CONFIG_NO_EXCEPTIONS_SEH +# include // for ExceptionCodes +# else // already included: +# endif #else # include #endif @@ -1260,7 +1273,11 @@ struct error_traits { static void rethrow( Error const & /*e*/ ) { +#if nsel_CONFIG_NO_EXCEPTIONS_SEH + RaiseException( EXCEPTION_ACCESS_VIOLATION, EXCEPTION_NONCONTINUABLE, 0, NULL ); +#else assert( false && detail::text("throw bad_expected_access{ e };") ); +#endif } }; @@ -1269,7 +1286,11 @@ struct error_traits< std::exception_ptr > { static void rethrow( std::exception_ptr const & /*e*/ ) { +#if nsel_CONFIG_NO_EXCEPTIONS_SEH + RaiseException( EXCEPTION_ACCESS_VIOLATION, EXCEPTION_NONCONTINUABLE, 0, NULL ); +#else assert( false && detail::text("throw bad_expected_access{ e };") ); +#endif } }; @@ -1278,7 +1299,11 @@ struct error_traits< std::error_code > { static void rethrow( std::error_code const & /*e*/ ) { +#if nsel_CONFIG_NO_EXCEPTIONS_SEH + RaiseException( EXCEPTION_ACCESS_VIOLATION, EXCEPTION_NONCONTINUABLE, 0, NULL ); +#else assert( false && detail::text("throw std::system_error( e );") ); +#endif } }; @@ -1639,10 +1664,11 @@ public: return *this; } - template< typename G + template< typename G = E nsel_REQUIRES_T( - std::is_copy_constructible::value // TODO: std::is_nothrow_copy_constructible - && std::is_copy_assignable::value + std::is_constructible::value && + std::is_copy_constructible::value // TODO: std::is_nothrow_copy_constructible + && std::is_copy_assignable::value ) > expected & operator=( nonstd::unexpected_type const & error ) @@ -1651,10 +1677,11 @@ public: return *this; } - template< typename G + template< typename G = E nsel_REQUIRES_T( - std::is_move_constructible::value // TODO: std::is_nothrow_move_constructible - && std::is_move_assignable::value + std::is_constructible::value && + std::is_move_constructible::value // TODO: std::is_nothrow_move_constructible + && std::is_move_assignable::value ) > expected & operator=( nonstd::unexpected_type && error ) @@ -1742,12 +1769,12 @@ public: constexpr value_type const && operator *() const && { - return assert( has_value() ), std::move( contained.value() ); + return std::move( ( assert( has_value() ), contained.value() ) ); } nsel_constexpr14 value_type && operator *() && { - return assert( has_value() ), std::move( contained.value() ); + return std::move( ( assert( has_value() ), contained.value() ) ); } #endif @@ -1808,12 +1835,12 @@ public: constexpr error_type const && error() const && { - return assert( ! has_value() ), std::move( contained.error() ); + return std::move( ( assert( ! has_value() ), contained.error() ) ); } error_type && error() && { - return assert( ! has_value() ), std::move( contained.error() ); + return std::move( ( assert( ! has_value() ), contained.error() ) ); } #endif @@ -2080,12 +2107,12 @@ public: constexpr error_type const && error() const && { - return assert( ! has_value() ), std::move( contained.error() ); + return std::move( ( assert( ! has_value() ), contained.error() ) ); } error_type && error() && { - return assert( ! has_value() ), std::move( contained.error() ); + return std::move( ( assert( ! has_value() ), contained.error() ) ); } #endif