xref: /minix3/external/bsd/llvm/dist/clang/test/SemaTemplate/alignas.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -std=c++11 -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // expected-no-diagnostics
4*f4a2713aSLionel Sambuc using size_t = decltype(sizeof(0));
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc template<typename T, typename U>
max(T t,U u)7*f4a2713aSLionel Sambuc constexpr T max(T t, U u) { return t > u ? t : u; }
8*f4a2713aSLionel Sambuc 
9*f4a2713aSLionel Sambuc template<typename T, typename ...Ts>
max(T t,Ts...ts)10*f4a2713aSLionel Sambuc constexpr auto max(T t, Ts ...ts) -> decltype(max(t, max(ts...))) {
11*f4a2713aSLionel Sambuc   return max(t, max(ts...));
12*f4a2713aSLionel Sambuc }
13*f4a2713aSLionel Sambuc 
14*f4a2713aSLionel Sambuc template<typename...T> struct my_union {
15*f4a2713aSLionel Sambuc   alignas(T...) char buffer[max(sizeof(T)...)];
16*f4a2713aSLionel Sambuc };
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc struct alignas(8) A { char c; };
19*f4a2713aSLionel Sambuc struct alignas(4) B { short s; };
20*f4a2713aSLionel Sambuc struct C { char a[16]; };
21*f4a2713aSLionel Sambuc 
22*f4a2713aSLionel Sambuc static_assert(sizeof(my_union<A, B, C>) == 16, "");
23*f4a2713aSLionel Sambuc static_assert(alignof(my_union<A, B, C>) == 8, "");
24