blob: 4281895f40ed9b1c451b18c638c8906fea634ef6 [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
Sean Huntbbd37c62009-11-21 08:43:09 +00002
Peter Collingbourne82d0b0a2011-09-29 18:04:28 +00003int align_illegal alignas(3); //expected-error {{requested alignment is not a power of 2}}
4char align_big alignas(int);
5int align_small alignas(1); // FIXME: this should be rejected
6int align_multiple alignas(1) alignas(8) alignas(1);
Sean Huntbbd37c62009-11-21 08:43:09 +00007
8struct align_member {
Peter Collingbourne82d0b0a2011-09-29 18:04:28 +00009 int member alignas(8);
Sean Huntbbd37c62009-11-21 08:43:09 +000010};
11
Eli Friedmanfc038e92011-12-17 00:36:09 +000012template <unsigned A> struct alignas(A) align_class_template {};
Peter Collingbourne0661bd0c2011-10-23 17:07:16 +000013
Peter Collingbourne0b64ba92011-10-23 20:07:52 +000014// FIXME: these should not error
15template <typename... T> alignas(T...) struct align_class_temp_pack_type {}; // expected-error{{pack expansions in alignment specifiers are not supported yet}}
16template <unsigned... A> alignas(A...) struct align_class_temp_pack_expr {}; // expected-error{{pack expansions in alignment specifiers are not supported yet}}
17
Peter Collingbourne82d0b0a2011-09-29 18:04:28 +000018typedef char align_typedef alignas(8);
Richard Smith3e4c6c42011-05-05 21:57:07 +000019template<typename T> using align_alias_template = align_typedef;
20
Sean Huntbbd37c62009-11-21 08:43:09 +000021static_assert(alignof(align_big) == alignof(int), "k's alignment is wrong");
John McCall4081a5c2010-10-08 18:24:19 +000022static_assert(alignof(align_small) == 1, "j's alignment is wrong");
Sean Huntbbd37c62009-11-21 08:43:09 +000023static_assert(alignof(align_multiple) == 8, "l's alignment is wrong");
24static_assert(alignof(align_member) == 8, "quuux's alignment is wrong");
25static_assert(sizeof(align_member) == 8, "quuux's size is wrong");
Richard Smith3e4c6c42011-05-05 21:57:07 +000026static_assert(alignof(align_typedef) == 8, "typedef's alignment is wrong");
Peter Collingbourne0661bd0c2011-10-23 17:07:16 +000027static_assert(alignof(align_class_template<8>) == 8, "template's alignment is wrong");
28static_assert(alignof(align_class_template<16>) == 16, "template's alignment is wrong");
Peter Collingbourne0b64ba92011-10-23 20:07:52 +000029// FIXME: enable these tests
30// static_assert(alignof(align_class_temp_pack_type<short, int, long>) == alignof(long), "template's alignment is wrong");
31// static_assert(alignof(align_class_temp_pack_expr<8, 16, 32>) == 32, "template's alignment is wrong");
Richard Smith3e4c6c42011-05-05 21:57:07 +000032static_assert(alignof(align_alias_template<int>) == 8, "alias template's alignment is wrong");