From 8c9b385288609fa4af9df746464b26130c9034b1 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 29 Nov 2018 12:32:57 +0000 Subject: [PATCH] PR libstdc++/88119 use alignof in std::alignment_of, not __alignof__ Now that __alignof__ and alignof sometimes disagree it matters which one we use. The standard says that std::alignment_of::value equals alignof(T), so we need to use that. Change the only uses of alignment_of to use __alignof__ to avoid a change in alignment. PR libstdc++/88119 * include/ext/aligned_buffer.h (__aligned_membuf): Add comment. (__aligned_buffer): Use __alignof__ instead of std::alignment_of. * include/std/type_traits (alignment_of): Use alignof instead of __alignof__. * testsuite/20_util/alignment_of/value.cc: Fix test to check values match alignof not __alignof__, as required by the standard. From-SVN: r266613 --- libstdc++-v3/ChangeLog | 8 ++++++ libstdc++-v3/include/ext/aligned_buffer.h | 7 ++--- libstdc++-v3/include/std/type_traits | 2 +- .../testsuite/20_util/alignment_of/value.cc | 26 ++++++++++++------- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 607edb9beb3..553be512ec5 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,13 @@ 2018-11-29 Jonathan Wakely + PR libstdc++/88119 + * include/ext/aligned_buffer.h (__aligned_membuf): Add comment. + (__aligned_buffer): Use __alignof__ instead of std::alignment_of. + * include/std/type_traits (alignment_of): Use alignof instead of + __alignof__. + * testsuite/20_util/alignment_of/value.cc: Fix test to check values + match alignof not __alignof__, as required by the standard. + PR libstdc++/86910 PR libstdc++/87846 * src/filesystem/ops.cc (experimental::create_directories): Report diff --git a/libstdc++-v3/include/ext/aligned_buffer.h b/libstdc++-v3/include/ext/aligned_buffer.h index 81fb797723c..2fc8f12e62d 100644 --- a/libstdc++-v3/include/ext/aligned_buffer.h +++ b/libstdc++-v3/include/ext/aligned_buffer.h @@ -49,6 +49,8 @@ namespace __gnu_cxx // Target macro ADJUST_FIELD_ALIGN can produce different alignment for // types when used as class members. __aligned_membuf is intended // for use as a class member, so align the buffer as for a class member. + // Since GCC 8 we could just use alignof(_Tp) instead, but older + // versions of non-GNU compilers might still need this trick. struct _Tp2 { _Tp _M_t; }; alignas(__alignof__(_Tp2::_M_t)) unsigned char _M_storage[sizeof(_Tp)]; @@ -86,11 +88,10 @@ namespace __gnu_cxx // This type is still used to avoid an ABI change. template struct __aligned_buffer - : std::aligned_storage::value> + : std::aligned_storage { typename - std::aligned_storage::value>::type - _M_storage; + std::aligned_storage::type _M_storage; __aligned_buffer() = default; diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 60094f9897b..727a5451c56 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1286,7 +1286,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// alignment_of template struct alignment_of - : public integral_constant { }; + : public integral_constant { }; /// rank template diff --git a/libstdc++-v3/testsuite/20_util/alignment_of/value.cc b/libstdc++-v3/testsuite/20_util/alignment_of/value.cc index 7c46a58bf28..f73008daabd 100644 --- a/libstdc++-v3/testsuite/20_util/alignment_of/value.cc +++ b/libstdc++-v3/testsuite/20_util/alignment_of/value.cc @@ -20,16 +20,22 @@ #include #include +template +constexpr bool test() +{ + return __gnu_test::test_property(alignof(T)); +} + void test01() { - using std::alignment_of; - using namespace __gnu_test; - - static_assert(test_property(__alignof__(char)), ""); - static_assert(test_property(__alignof__(short)), ""); - static_assert(test_property(__alignof__(int)), ""); - static_assert(test_property(__alignof__(double)), ""); - static_assert(test_property(__alignof__(int[4])), ""); - static_assert(test_property(__alignof__(ClassType)), ""); + static_assert(test(), ""); + static_assert(test(), ""); + static_assert(test(), ""); + static_assert(test(), ""); + static_assert(test(), ""); + static_assert(test(), ""); + static_assert(test(), ""); + static_assert(test(), ""); + static_assert(test(), ""); + static_assert(test<__gnu_test::ClassType>(), ""); }