1 // { dg-do compile { target c++11 } }
2 
3 // 2014-04-16 Rüdiger Sonderfeld  <ruediger@c-plusplus.de>
4 
5 // Copyright (C) 2014-2020 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library.  This library is free
8 // software; you can redistribute it and/or modify it under the terms
9 // of the GNU General Public License as published by the Free Software
10 // Foundation; either version 3, or (at your option) any later
11 // version.
12 
13 // This library is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 // General Public License for more details.
17 
18 // You should have received a copy of the GNU General Public License
19 // along with this library; see the file COPYING3.  If not see
20 // <http://www.gnu.org/licenses/>.
21 
22 // C++11 [meta.trans.other] 20.9.7.6: aligned_union
23 
24 #include <type_traits>
25 #include <testsuite_tr1.h>
26 
27 struct MSAlignType { } __attribute__((__aligned__));
28 
29 template<typename...T>
30   struct mymax
31   {
32     static const std::size_t alignment = 0;
33     static const std::size_t size = 0;
34   };
35 
36 template<typename L,  typename...T>
37   struct mymax<L, T...>
38   {
39     static const std::size_t alignment = alignof(L) > mymax<T...>::alignment
40       ? alignof(L) : mymax<T...>::alignment;
41     static const std::size_t size = sizeof(L) > mymax<T...>::size
42       ? sizeof(L) : mymax<T...>::size;
43   };
44 
test01()45 void test01()
46 {
47   using std::aligned_union;
48   using std::alignment_of;
49   using std::size_t;
50   using namespace __gnu_test;
51 
52   const size_t max_a = mymax<char, short, int, double, int[4],
53                              ClassType, MSAlignType>::alignment;
54   const size_t max_s = mymax<char, short, int, double, int[4],
55                              ClassType, MSAlignType>::size;
56 
57   typedef aligned_union<0, char, short, int, double, int[4],
58                         ClassType, MSAlignType> au_type;
59   static_assert(au_type::alignment_value == max_a, "Alignment value");
60   static_assert(sizeof(au_type::type) >= max_s, "Storage size");
61 
62   typedef aligned_union<max_s+100, char, short, int, double, int[4],
63                         ClassType, MSAlignType> au_type2;
64   static_assert(sizeof(au_type2::type) >= max_s+100,
65                 "Storage size (at least len)");
66 }
67 
main()68 int main()
69 {
70   test01();
71 }
72