From 0d9b18f4e960ddad7eecc0d01a99d0c30e2b4803 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 16 Nov 2022 15:10:57 +0100 Subject: compat/fu2: fix it --- compat/function2.hpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/compat/function2.hpp b/compat/function2.hpp index 542c72ba..07b40338 100644 --- a/compat/function2.hpp +++ b/compat/function2.hpp @@ -7,9 +7,17 @@ #ifndef FU2_INCLUDED_FUNCTION2_HPP_ #define FU2_INCLUDED_FUNCTION2_HPP_ +#ifdef __GNUG__ +#pragma GCC system_header +#elif defined _MSC_VER +#pragma system_header +#endif + +#define FU2_WITH_DISABLED_EXCEPTIONS +#define FU2_WITH_NO_FUNCTIONAL_HEADER #include #include -#include +//#include #include #include #include @@ -207,7 +215,7 @@ struct property { #ifndef NDEBUG [[noreturn]] inline void unreachable_debug() { FU2_DETAIL_TRAP(); - std::abort(); + *(volatile int*)nullptr = 0; } #endif @@ -338,13 +346,13 @@ namespace type_erasure { template struct address_taker { template - static void* take(O&& obj) { - return std::addressof(obj); + static constexpr void* take(O&& obj) { + return (void*)std::addressof(obj); } - static T& restore(void* ptr) { + static constexpr T& restore(void* ptr) { return *static_cast(ptr); } - static T const& restore(void const* ptr) { + static constexpr T const& restore(void const* ptr) { return *static_cast(ptr); } static T volatile& restore(void volatile* ptr) { @@ -1074,7 +1082,9 @@ struct internal_capacity { /// Tag to access the structure in a type-safe way data_accessor accessor_; /// The internal capacity we use to allocate in-place - std::aligned_storage_t capacity_; + struct { + alignas(Capacity::alignment) unsigned char data[Capacity::capacity]; + } capacity_; } type; }; template @@ -1595,15 +1605,15 @@ public: FU2_DETAIL_CXX14_CONSTEXPR function(std::nullptr_t np) : erasure_(np) { } - function& operator=(function const& /*right*/) = default; - function& operator=(function&& /*right*/) = default; + constexpr function& operator=(function const& /*right*/) = default; + constexpr function& operator=(function&& /*right*/) = default; /// Copy assigning from another copyable function template * = nullptr, enable_if_copyable_correct_t* = nullptr, enable_if_owning_correct_t* = nullptr> - function& operator=(function const& right) { + constexpr function& operator=(function const& right) { erasure_ = right.erasure_; return *this; } @@ -1612,7 +1622,7 @@ public: template * = nullptr, enable_if_owning_correct_t* = nullptr> - function& operator=(function&& right) { + constexpr function& operator=(function&& right) { erasure_ = std::move(right.erasure_); return *this; } @@ -1623,13 +1633,13 @@ public: enable_if_can_accept_all_t* = nullptr, assert_wrong_copy_assign_t* = nullptr, assert_no_strong_except_guarantee_t* = nullptr> - function& operator=(T&& callable) { + constexpr function& operator=(T&& callable) { erasure_.assign(use_bool_op>{}, std::forward(callable)); return *this; } /// Clears the function - function& operator=(std::nullptr_t np) { + constexpr function& operator=(std::nullptr_t np) { erasure_ = np; return *this; } -- cgit v1.2.3