]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/aligned_union/1.cc
1 // { dg-do compile { target c++11 } }
3 // 2014-04-16 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
5 // Copyright (C) 2014-2018 Free Software Foundation, Inc.
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
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.
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/>.
22 // C++11 [meta.trans.other] 20.9.7.6: aligned_union
24 #include <type_traits>
25 #include <testsuite_tr1.h>
27 struct MSAlignType
{ } __attribute__((__aligned__
));
29 template<typename
...T
>
32 static const std::size_t alignment
= 0;
33 static const std::size_t size
= 0;
36 template<typename L
, typename
...T
>
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
;
47 using std::aligned_union
;
48 using std::alignment_of
;
50 using namespace __gnu_test
;
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
;
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");
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)");