From 0173564c24d2665429e6f766cfe456df97def441 Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sun, 1 Mar 2020 12:53:47 +0300 Subject: [PATCH 1/2] Added tests for alignas involving constant expressions. Some compilers (e.g. gcc 4.8) are known to require a literal constant in alignas and not supporting a constant expression. The test was modified to detect that. --- test/boost_no_cxx11_alignas.ipp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/test/boost_no_cxx11_alignas.ipp b/test/boost_no_cxx11_alignas.ipp index afd428f6..53342215 100644 --- a/test/boost_no_cxx11_alignas.ipp +++ b/test/boost_no_cxx11_alignas.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Andrey Semashev 2013 +// (C) Copyright Andrey Semashev 2013, 2020 // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file @@ -12,6 +12,12 @@ namespace boost_no_cxx11_alignas { +template< unsigned int Alignment > +struct alignment +{ + static const unsigned int value = Alignment; +}; + struct alignas(16) my_data1 { char data[10]; @@ -22,10 +28,17 @@ struct alignas(double) my_data2 char data[16]; }; +struct alignas(alignment< 16u >::value) my_data3 +{ + char data[16]; +}; + my_data1 dummy1[2]; my_data2 dummy2; -alignas(16) char dummy3[10]; -alignas(double) char dummy4[32]; +my_data3 dummy3; +alignas(16) char dummy4[10]; +alignas(double) char dummy5[32]; +alignas(alignment< 16u >::value) char dummy6[32]; int test() { From c3f81f3c7024ab5428859b8fa9cdf256c73c93ee Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Sun, 1 Mar 2020 12:59:03 +0300 Subject: [PATCH 2/2] Increase gcc version to 4.9 for alignas. gcc 4.8 is known to not support alignas with constant expressions. --- include/boost/config/compiler/gcc.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/boost/config/compiler/gcc.hpp b/include/boost/config/compiler/gcc.hpp index 78f1ae39..d6fbda0e 100644 --- a/include/boost/config/compiler/gcc.hpp +++ b/include/boost/config/compiler/gcc.hpp @@ -254,7 +254,6 @@ // C++0x features in 4.8.n and later // #if (BOOST_GCC_VERSION < 40800) || !defined(BOOST_GCC_CXX11) -# define BOOST_NO_CXX11_ALIGNAS # define BOOST_NO_CXX11_THREAD_LOCAL # define BOOST_NO_CXX11_SFINAE_EXPR #endif @@ -267,6 +266,14 @@ # define BOOST_NO_CXX14_BINARY_LITERALS #endif +// C++0x features in 4.9.n and later +// +#if (BOOST_GCC_VERSION < 40900) || !defined(BOOST_GCC_CXX11) +// Although alignas support is added in gcc 4.8, it does not accept +// constant expressions as an argument until gcc 4.9. +# define BOOST_NO_CXX11_ALIGNAS +#endif + // C++0x features in 5.1 and later // #if (BOOST_GCC_VERSION < 50100) || !defined(BOOST_GCC_CXX11)