1// { dg-options " -std=gnu++11 " } 2// { dg-do compile } 3 4// 2014-04-16 R��diger Sonderfeld <ruediger@c-plusplus.de> 5 6// Copyright (C) 2014-2015 Free Software Foundation, Inc. 7// 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 12// version. 13 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. 18 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/>. 22 23// C++11 [meta.trans.other] 20.9.7.6: aligned_union 24 25#include <type_traits> 26#include <testsuite_tr1.h> 27 28struct MSAlignType { } __attribute__((__aligned__)); 29 30template<typename...T> 31 struct mymax 32 { 33 static const std::size_t alignment = 0; 34 static const std::size_t size = 0; 35 }; 36 37template<typename L, typename...T> 38 struct mymax<L, T...> 39 { 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; 44 }; 45 46void test01() 47{ 48 using std::aligned_union; 49 using std::alignment_of; 50 using std::size_t; 51 using namespace __gnu_test; 52 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; 57 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"); 62 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)"); 67} 68 69int main() 70{ 71 test01(); 72} 73