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 | enum alignas(1) E1 {}; // expected-error {{requested alignment is less than minimum alignment of 4 for type 'E1'}} |
15 | enum alignas(1) E2 : char {}; // ok |
16 | enum alignas(4) E3 { e3 = 0 }; // ok |
17 | enum alignas(4) E4 { e4 = 1ull << 33 }; // expected-error {{requested alignment is less than minimum alignment of 8 for type 'E4'}} |
18 | enum alignas(8) E5 {}; |
19 | static_assert(alignof(E5) == 8, ""); |
20 | |
21 | typedef __attribute__((aligned(16))) int IntAlign16; |
22 | enum E6 : IntAlign16 {}; |
23 | static_assert(alignof(E6) == 4, ""); |
24 | |
25 | struct S1 { |
26 | alignas(8) int n; |
27 | }; |
28 | struct alignas(2) S2 { // expected-error {{requested alignment is less than minimum alignment of 4 for type 'S2'}} |
29 | int n; |
30 | }; |
31 | struct alignas(2) S3 { // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S3'}} |
32 | S1 s1; |
33 | }; |
34 | struct alignas(2) S4 : S1 { // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S4'}} |
35 | }; |
36 | struct S5 : S1 { |
37 | alignas(2) S1 s1; // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S1'}} |
38 | }; |
39 | struct S6 { |
40 | S1 s1; |
41 | }; |
42 | struct S7 : S1 { |
43 | }; |
44 | struct alignas(2) alignas(8) alignas(1) S8 : S1 { |
45 | }; |
46 | |
47 | S1 s1 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S1'}} |
48 | S6 s6 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S6'}} |
49 | S7 s7 alignas(4); // expected-error {{requested alignment is less than minimum alignment of 8 for type 'S7'}} |
50 | |
51 | template<int N, int M, typename T> |
52 | struct alignas(N) X { // expected-error 3{{requested alignment is less than minimum}} |
53 | alignas(M) T t; // expected-error 3{{requested alignment is less than minimum}} |
54 | }; |
55 | |
56 | template struct X<1, 1, char>; |
57 | template struct X<4, 1, char>; |
58 | template struct X<1, 2, char>; // expected-note {{instantiation}} |
59 | template struct X<1, 1, short>; // expected-note {{instantiation}} |
60 | template struct X<2, 1, short>; // expected-note {{instantiation}} |
61 | template struct X<2, 2, short>; |
62 | template struct X<16, 8, S1>; |
63 | template struct X<4, 4, S1>; // expected-note {{instantiation}} |
64 | |
65 | template<int N, typename T> |
66 | struct Y { |
67 | enum alignas(N) E : T {}; // expected-error {{requested alignment is less than minimum}} |
68 | }; |
69 | template struct Y<1, char>; |
70 | template struct Y<2, char>; |
71 | template struct Y<1, short>; // expected-note {{instantiation}} |
72 | template struct Y<2, short>; |
73 | |
74 | template<int N, typename T> |
75 | void f() { |
76 | alignas(N) T v; // expected-error {{requested alignment is less than minimum}} |
77 | }; |
78 | template void f<1, char>(); |
79 | template void f<2, char>(); |
80 | template void f<1, short>(); // expected-note {{instantiation}} |
81 | template void f<2, short>(); |
82 | |