| 1 |
// RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -verify %s |
| 2 |
|
| 3 |
alignas(1) int n1; // expected-error {{requested alignment is less than minimum alignment of 4 for type 'int'}} |
| 4 |
alignas(1) alignas(2) int n2; // expected-error {{less than minimum alignment}} |
| 5 |
alignas(1) alignas(2) alignas(4) int n3; // ok |
| 6 |
alignas(1) alignas(2) alignas(0) int n4; // expected-error {{less than minimum alignment}} |
| 7 |
alignas(1) alignas(2) int n5 alignas(4); // ok |
| 8 |
alignas(1) alignas(4) int n6 alignas(2); // ok |
| 9 |
alignas(1) int n7 alignas(2), // expected-error {{less than minimum alignment}} |
| 10 |
n8 alignas(4); // ok |
| 11 |
alignas(8) int n9 alignas(2); // ok, overaligned |
| 12 |
alignas(1) extern int n10; // expected-error {{less than minimum alignment}} |
| 13 |
|
| 14 |
typedef __attribute__((aligned(16))) int IntAlign16; |
| 15 |
enum E6 : IntAlign16 {}; |
| 16 |
static_assert(alignof(E6) == 4, ""); |
| 17 |
|
| 18 |
struct S1 { |
| 19 |
alignas(8) int n; |
| 20 |
}; |
| 21 |
struct alignas(2) S2 { // expected-error {{requested alignment is less than minimum alignment of 4 for type 'S2'}} |
| 22 |
int n; |
| 23 |
}; |
| 24 |
struct alignas(2) S3 { // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S3'}} |
| 25 |
S1 s1; |
| 26 |
}; |
| 27 |
struct alignas(2) S4 : S1 { // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S4'}} |
| 28 |
}; |
| 29 |
struct S5 : S1 { |
| 30 |
alignas(2) S1 s1; // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S1'}} |
| 31 |
}; |
| 32 |
struct S6 { |
| 33 |
S1 s1; |
| 34 |
}; |
| 35 |
struct S7 : S1 { |
| 36 |
}; |
| 37 |
struct alignas(2) alignas(8) alignas(1) S8 : S1 { |
| 38 |
}; |
| 39 |
|
| 40 |
S1 s1 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S1'}} |
| 41 |
S6 s6 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S6'}} |
| 42 |
S7 s7 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S7'}} |
| 43 |
|
| 44 |
template<int N, int M, typename T> |
| 45 |
struct alignas(N) X { // expected-error 3{{requested alignment is less than minimum}} |
| 46 |
alignas(M) T t; // expected-error 3{{requested alignment is less than minimum}} |
| 47 |
}; |
| 48 |
|
| 49 |
template struct X<1, 1, char>; |
| 50 |
template struct X<4, 1, char>; |
| 51 |
template struct X<1, 2, char>; // expected-note {{instantiation}} |
| 52 |
template struct X<1, 1, short>; // expected-note {{instantiation}} |
| 53 |
template struct X<2, 1, short>; // expected-note {{instantiation}} |
| 54 |
template struct X<2, 2, short>; |
| 55 |
template struct X<16, 8, S1>; |
| 56 |
template struct X<4, 4, S1>; // expected-note {{instantiation}} |
| 57 |
|
| 58 |
template<int N, typename T> |
| 59 |
void f() { |
| 60 |
alignas(N) T v; // expected-error {{requested alignment is less than minimum}} |
| 61 |
}; |
| 62 |
template void f<1, char>(); |
| 63 |
template void f<2, char>(); |
| 64 |
template void f<1, short>(); // expected-note {{instantiation}} |
| 65 |
template void f<2, short>(); |