Richard Smith | 44c247f | 2013-02-22 08:32:16 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -verify %s |
| 2 | |
| 3 | // expected-no-diagnostics |
| 4 | using size_t = decltype(sizeof(0)); |
| 5 | |
| 6 | template<typename T, typename U> |
| 7 | constexpr T max(T t, U u) { return t > u ? t : u; } |
| 8 | |
| 9 | template<typename T, typename ...Ts> |
| 10 | constexpr auto max(T t, Ts ...ts) -> decltype(max(t, max(ts...))) { |
| 11 | return max(t, max(ts...)); |
| 12 | } |
| 13 | |
| 14 | template<typename...T> struct my_union { |
| 15 | alignas(T...) char buffer[max(sizeof(T)...)]; |
| 16 | }; |
| 17 | |
| 18 | struct alignas(8) A { char c; }; |
| 19 | struct alignas(4) B { short s; }; |
| 20 | struct C { char a[16]; }; |
| 21 | |
| 22 | static_assert(sizeof(my_union<A, B, C>) == 16, ""); |
| 23 | static_assert(alignof(my_union<A, B, C>) == 8, ""); |
Richard Smith | 0228491 | 2018-01-04 01:02:18 +0000 | [diff] [blame] | 24 | |
| 25 | namespace PR35028 { |
| 26 | template<class X, int Alignment> struct alignas(X) alignas(long long) alignas(long double) alignas(Alignment) Aligned { |
| 27 | union { |
| 28 | long long align1; |
| 29 | long double align2; |
| 30 | char data[sizeof(X)]; |
| 31 | }; |
| 32 | }; |
| 33 | Aligned<int, 1> a; |
| 34 | } |