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