From 270bb80fbb3ee8c14009d8bbb6eb05bdc121bfb1 Mon Sep 17 00:00:00 2001 From: redi Date: Mon, 2 Jun 2014 13:55:14 +0000 Subject: [PATCH] =?utf8?q?2014-06-02=20=20R=C3=BCdiger=20Sonderfeld=20=20=20=09=20=20=20=20Jonathan=20Wakely=20=20?= =?utf8?q??= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * libstdc++-v3/include/std/type_traits (__strictest_alignment): New helper struct. (aligned_union): New struct (C++11). (aligned_union_t): New type alias (C++14). * doc/xml/manual/status_cxx2011.xml: Update. * libstdc++-v3/testsuite/20_util/aligned_union/1.cc: New file. * testsuite/20_util/declval/requirements/1_neg.cc: Adjust dg-error line number. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@211137 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 12 ++++ libstdc++-v3/doc/xml/manual/status_cxx2011.xml | 5 +- libstdc++-v3/include/std/type_traits | 49 +++++++++++++++ libstdc++-v3/testsuite/20_util/aligned_union/1.cc | 72 ++++++++++++++++++++++ .../20_util/declval/requirements/1_neg.cc | 2 +- 5 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 libstdc++-v3/testsuite/20_util/aligned_union/1.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 56e7d3472d7..885718fb5dd 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,15 @@ +2014-06-02 RĂ¼diger Sonderfeld + Jonathan Wakely + + * libstdc++-v3/include/std/type_traits (__strictest_alignment): New + helper struct. + (aligned_union): New struct (C++11). + (aligned_union_t): New type alias (C++14). + * doc/xml/manual/status_cxx2011.xml: Update. + * libstdc++-v3/testsuite/20_util/aligned_union/1.cc: New file. + * testsuite/20_util/declval/requirements/1_neg.cc: Adjust dg-error + line number. + 2014-06-01 Jonathan Wakely PR libstdc++/61374 diff --git a/libstdc++-v3/doc/xml/manual/status_cxx2011.xml b/libstdc++-v3/doc/xml/manual/status_cxx2011.xml index b3c24d888c7..cad41112505 100644 --- a/libstdc++-v3/doc/xml/manual/status_cxx2011.xml +++ b/libstdc++-v3/doc/xml/manual/status_cxx2011.xml @@ -871,11 +871,10 @@ particular release. - 20.9.7.6 Other transformations - Partial - Missing aligned_union. + Y + 20.10 diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 1ff2e625a73..da8a95f034e 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -1870,6 +1870,52 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; }; + template + struct __strictest_alignment + { + static const size_t _S_alignment = 0; + static const size_t _S_size = 0; + }; + + template + struct __strictest_alignment<_Tp, _Types...> + { + static const size_t _S_alignment = + alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment + ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment; + static const size_t _S_size = + sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size + ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size; + }; + + /** + * @brief Provide aligned storage for types. + * + * [meta.trans.other] + * + * Provides aligned storage for any of the provided types of at + * least size _Len. + * + * @see aligned_storage + */ + template + struct aligned_union + { + private: + static_assert(sizeof...(_Types) != 0, "At least one type is required"); + + using __strictest = __strictest_alignment<_Types...>; + static const size_t _S_len = _Len > __strictest::_S_size + ? _Len : __strictest::_S_size; + public: + /// The value of the strictest alignment of _Types. + static const size_t alignment_value = __strictest::_S_alignment; + /// The storage. + typedef typename aligned_storage<_S_len, alignment_value>::type type; + }; + + template + const size_t aligned_union<_Len, _Types...>::alignment_value; // Decay trait for arrays and functions, used for perfect forwarding // in make_pair, make_tuple, etc. @@ -2206,6 +2252,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __alignof__(typename __aligned_storage_msa<_Len>::__type)> using aligned_storage_t = typename aligned_storage<_Len, _Align>::type; + template + using aligned_union_t = typename aligned_union<_Len, _Types...>::type; + /// Alias template for decay template using decay_t = typename decay<_Tp>::type; diff --git a/libstdc++-v3/testsuite/20_util/aligned_union/1.cc b/libstdc++-v3/testsuite/20_util/aligned_union/1.cc new file mode 100644 index 00000000000..5285bb044fc --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/aligned_union/1.cc @@ -0,0 +1,72 @@ +// { dg-options " -std=gnu++11 " } +// { dg-do compile } + +// 2014-04-16 RĂ¼diger Sonderfeld + +// Copyright (C) 2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// . + +// C++11 [meta.trans.other] 20.9.7.6: aligned_union + +#include +#include + +struct MSAlignType { } __attribute__((__aligned__)); + +template + struct mymax + { + static const std::size_t alignment = 0; + static const std::size_t size = 0; + }; + +template + struct mymax + { + static const std::size_t alignment = alignof(L) > mymax::alignment + ? alignof(L) : mymax::alignment; + static const std::size_t size = sizeof(L) > mymax::size + ? sizeof(L) : mymax::size; + }; + +void test01() +{ + using std::aligned_union; + using std::alignment_of; + using std::size_t; + using namespace __gnu_test; + + const size_t max_a = mymax::alignment; + const size_t max_s = mymax::size; + + typedef aligned_union<0, char, short, int, double, int[4], + ClassType, MSAlignType> au_type; + static_assert(au_type::alignment_value == max_a, "Alignment value"); + static_assert(sizeof(au_type::type) >= max_s, "Storage size"); + + typedef aligned_union au_type2; + static_assert(sizeof(au_type2::type) >= max_s+100, + "Storage size (at least len)"); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc index 04e6b711906..774858cafdc 100644 --- a/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc +++ b/libstdc++-v3/testsuite/20_util/declval/requirements/1_neg.cc @@ -19,7 +19,7 @@ // with this library; see the file COPYING3. If not see // . -// { dg-error "static assertion failed" "" { target *-*-* } 2036 } +// { dg-error "static assertion failed" "" { target *-*-* } 2082 } #include -- 2.11.4.GIT