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