From bdc9d6955f4b5425a080d128b889704308fa9f63 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 14 Nov 2021 05:59:06 -0800 Subject: [PATCH] Workaround a GCC bug with noexcept(this->...) --- common/aloptional.h | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/common/aloptional.h b/common/aloptional.h index b76bebf1..c83e1dc8 100644 --- a/common/aloptional.h +++ b/common/aloptional.h @@ -114,6 +114,11 @@ template && std::is_trivially_destructible::value> struct optional_storage; +/* Some versions of GCC have issues with 'this' in the following noexcept(...) + * statements, so this macro is a workaround. + */ +#define _this std::declval() + /* Completely trivial. */ template struct optional_storage : public optstore_helper { @@ -133,7 +138,7 @@ struct optional_storage : public optstore_helper constexpr optional_storage(const optional_storage&) = default; constexpr optional_storage(optional_storage&&) = default; constexpr optional_storage& operator=(const optional_storage&) = default; - constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(this->assign(std::move(rhs))) + constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(_this->assign(std::move(rhs))) { this->assign(std::move(rhs)); return *this; } }; @@ -143,10 +148,10 @@ struct optional_storage : public optstore_helper using optstore_helper::optstore_helper; constexpr optional_storage() noexcept = default; constexpr optional_storage(const optional_storage&) = default; - constexpr optional_storage(optional_storage&& rhs) NOEXCEPT_AS(this->construct(std::move(rhs.mValue))) + constexpr optional_storage(optional_storage&& rhs) NOEXCEPT_AS(_this->construct(std::move(rhs.mValue))) { if(rhs.mHasValue) this->construct(std::move(rhs.mValue)); } constexpr optional_storage& operator=(const optional_storage&) = default; - constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(this->assign(std::move(rhs))) + constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(_this->assign(std::move(rhs))) { this->assign(std::move(rhs)); return *this; } }; @@ -157,7 +162,7 @@ struct optional_storage : public optstore_helper constexpr optional_storage() noexcept = default; constexpr optional_storage(const optional_storage&) = default; constexpr optional_storage(optional_storage&&) = default; - constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(this->assign(rhs)) + constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(_this->assign(rhs)) { this->assign(rhs); return *this; } constexpr optional_storage& operator=(optional_storage&&) = default; }; @@ -167,10 +172,10 @@ template struct optional_storage : public optstore_helper { using optstore_helper::optstore_helper; constexpr optional_storage() noexcept = default; - constexpr optional_storage(const optional_storage &rhs) NOEXCEPT_AS(this->construct(rhs.mValue)) + constexpr optional_storage(const optional_storage &rhs) NOEXCEPT_AS(_this->construct(rhs.mValue)) { if(rhs.mHasValue) this->construct(rhs.mValue); } constexpr optional_storage(optional_storage&&) = default; - constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(this->assign(rhs)) + constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(_this->assign(rhs)) { this->assign(rhs); return *this; } constexpr optional_storage& operator=(optional_storage&&) = default; }; @@ -182,9 +187,9 @@ struct optional_storage : public optstore_helper constexpr optional_storage() noexcept = default; constexpr optional_storage(const optional_storage&) = default; constexpr optional_storage(optional_storage&&) = default; - constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(this->assign(rhs)) + constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(_this->assign(rhs)) { this->assign(rhs); return *this; } - constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(this->assign(std::move(rhs))) + constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(_this->assign(std::move(rhs))) { this->assign(std::move(rhs)); return *this; } }; @@ -194,11 +199,11 @@ struct optional_storage : public optstore_helper::optstore_helper; constexpr optional_storage() noexcept = default; constexpr optional_storage(const optional_storage&) = default; - constexpr optional_storage(optional_storage&& rhs) NOEXCEPT_AS(this->construct(std::move(rhs.mValue))) + constexpr optional_storage(optional_storage&& rhs) NOEXCEPT_AS(_this->construct(std::move(rhs.mValue))) { if(rhs.mHasValue) this->construct(std::move(rhs.mValue)); } - constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(this->assign(rhs)) + constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(_this->assign(rhs)) { this->assign(rhs); return *this; } - constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(this->assign(std::move(rhs))) + constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(_this->assign(std::move(rhs))) { this->assign(std::move(rhs)); return *this; } }; @@ -207,12 +212,12 @@ template struct optional_storage : public optstore_helper { using optstore_helper::optstore_helper; constexpr optional_storage() noexcept = default; - constexpr optional_storage(const optional_storage &rhs) NOEXCEPT_AS(this->construct(rhs.mValue)) + constexpr optional_storage(const optional_storage &rhs) NOEXCEPT_AS(_this->construct(rhs.mValue)) { if(rhs.mHasValue) this->construct(rhs.mValue); } constexpr optional_storage(optional_storage&&) = default; - constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(this->assign(rhs)) + constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(_this->assign(rhs)) { this->assign(rhs); return *this; } - constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(this->assign(std::move(rhs))) + constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(_this->assign(std::move(rhs))) { this->assign(std::move(rhs)); return *this; } }; @@ -221,16 +226,18 @@ template struct optional_storage : public optstore_helper { using optstore_helper::optstore_helper; constexpr optional_storage() noexcept = default; - constexpr optional_storage(const optional_storage &rhs) NOEXCEPT_AS(this->construct(rhs.mValue)) + constexpr optional_storage(const optional_storage &rhs) NOEXCEPT_AS(_this->construct(rhs.mValue)) { if(rhs.mHasValue) this->construct(rhs.mValue); } - constexpr optional_storage(optional_storage&& rhs) NOEXCEPT_AS(this->construct(std::move(rhs.mValue))) + constexpr optional_storage(optional_storage&& rhs) NOEXCEPT_AS(_this->construct(std::move(rhs.mValue))) { if(rhs.mHasValue) this->construct(std::move(rhs.mValue)); } - constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(this->assign(rhs)) + constexpr optional_storage& operator=(const optional_storage &rhs) NOEXCEPT_AS(_this->assign(rhs)) { this->assign(rhs); return *this; } - constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(this->assign(std::move(rhs))) + constexpr optional_storage& operator=(optional_storage&& rhs) NOEXCEPT_AS(_this->assign(std::move(rhs))) { this->assign(std::move(rhs)); return *this; } }; +#undef _this + } // namespace detail_ #define REQUIRES(...) bool rt_=true, std::enable_if_t = true