From ce80ca0ce8edd107359c92bbd9230c7ac2ebb17b Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sun, 1 Mar 2020 13:31:45 +0300 Subject: [PATCH] Added a workaround for gcc 4.8 not supporting alignas with a constant expression gcc 4.8 requires that the argument of alignas is a literal constant and does not accept a constant expression. This workaround is temporary, until Boost.Config updates BOOST_NO_CXX11_ALIGNAS: https://github.com/boostorg/config/pull/324 --- include/boost/atomic/detail/atomic_flag.hpp | 2 +- include/boost/atomic/detail/atomic_template.hpp | 2 +- include/boost/atomic/detail/config.hpp | 5 +++++ include/boost/atomic/detail/storage_traits.hpp | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/boost/atomic/detail/atomic_flag.hpp b/include/boost/atomic/detail/atomic_flag.hpp index abc8161..6dd338c 100644 --- a/include/boost/atomic/detail/atomic_flag.hpp +++ b/include/boost/atomic/detail/atomic_flag.hpp @@ -45,7 +45,7 @@ struct atomic_flag typedef atomics::detail::operations< 1u, false > operations; typedef operations::storage_type storage_type; -#if !defined(BOOST_NO_CXX11_ALIGNAS) +#if !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_ALIGNAS) alignas(operations::storage_alignment) storage_type m_storage; #else // Note: Some compilers cannot use constant expressions in alignment attributes, so we have to use the union trick diff --git a/include/boost/atomic/detail/atomic_template.hpp b/include/boost/atomic/detail/atomic_template.hpp index d54e67c..0b5191f 100644 --- a/include/boost/atomic/detail/atomic_template.hpp +++ b/include/boost/atomic/detail/atomic_template.hpp @@ -76,7 +76,7 @@ protected: static BOOST_CONSTEXPR_OR_CONST std::size_t storage_alignment = atomics::detail::alignment_of< value_type >::value <= operations::storage_alignment ? operations::storage_alignment : atomics::detail::alignment_of< value_type >::value; protected: -#if !defined(BOOST_NO_CXX11_ALIGNAS) +#if !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_ALIGNAS) alignas(storage_alignment) storage_type m_storage; #else // Note: Some compilers cannot use constant expressions in alignment attributes, so we have to use the union trick diff --git a/include/boost/atomic/detail/config.hpp b/include/boost/atomic/detail/config.hpp index a7fcbd6..fda98e3 100644 --- a/include/boost/atomic/detail/config.hpp +++ b/include/boost/atomic/detail/config.hpp @@ -54,6 +54,11 @@ #endif #endif // defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) +#if defined(BOOST_NO_CXX11_ALIGNAS) || (defined(BOOST_GCC) && (BOOST_GCC+0) < 40900) +// This macro indicates that the compiler doesn't support alignas with a constant expression as an argument +#define BOOST_ATOMIC_DETAIL_NO_CXX11_ALIGNAS +#endif + // Enable pointer/reference casts between storage and value when possible. // Note: Despite that MSVC does not employ strict aliasing rules for optimizations // and does not require an explicit markup for types that may alias, we still don't diff --git a/include/boost/atomic/detail/storage_traits.hpp b/include/boost/atomic/detail/storage_traits.hpp index 02e1325..ee968d4 100644 --- a/include/boost/atomic/detail/storage_traits.hpp +++ b/include/boost/atomic/detail/storage_traits.hpp @@ -42,7 +42,7 @@ BOOST_FORCEINLINE void non_atomic_load(T const volatile& from, T& to) BOOST_NOEX template< std::size_t Size, std::size_t Alignment = 1u > struct BOOST_ATOMIC_DETAIL_MAY_ALIAS buffer_storage { -#if !defined(BOOST_NO_CXX11_ALIGNAS) +#if !defined(BOOST_ATOMIC_DETAIL_NO_CXX11_ALIGNAS) alignas(Alignment) unsigned char data[Size]; #else union