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