blob: e9276cd2d9ee333d4da3821f5b1a79c66f2faabf [file] [log] [blame]
Richard Smith7132be12013-03-18 23:37:25 +00001// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -pedantic -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);
Richard Smithbe507b62013-02-01 08:12:08 +00005int align_small alignas(1); // expected-error {{requested alignment is less than minimum}}
Peter Collingbourne82d0b0a2011-09-29 18:04:28 +00006int align_multiple alignas(1) alignas(8) alignas(1);
Richard Smith4cd81c52013-01-29 09:02:09 +00007alignas(4) int align_before;
Sean Huntbbd37c62009-11-21 08:43:09 +00008
9struct align_member {
Peter Collingbourne82d0b0a2011-09-29 18:04:28 +000010 int member alignas(8);
Richard Smith4cd81c52013-01-29 09:02:09 +000011 int bitfield alignas(1) : 1; // expected-error {{}}
Sean Huntbbd37c62009-11-21 08:43:09 +000012};
13
Richard Smith4cd81c52013-01-29 09:02:09 +000014void f(alignas(1) char c) { // expected-error {{'alignas' attribute cannot be applied to a function parameter}}
15 alignas(1) register char k; // expected-error {{'alignas' attribute cannot be applied to a variable with 'register' storage class}}
16 try {
17 } catch (alignas(4) int n) { // expected-error {{'alignas' attribute cannot be applied to a 'catch' variable}}
18 }
19}
20
21
Eli Friedmanfc038e92011-12-17 00:36:09 +000022template <unsigned A> struct alignas(A) align_class_template {};
Peter Collingbourne0661bd0c2011-10-23 17:07:16 +000023
Richard Smithf6565a92013-02-22 08:32:16 +000024template <typename... T> struct alignas(T...) align_class_temp_pack_type {};
25template <unsigned... A> struct alignas(A...) align_class_temp_pack_expr {};
26struct alignas(int...) alignas_expansion_no_packs {}; // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
27template <typename... A> struct outer {
28 template <typename... B> struct alignas(alignof(A) * alignof(B)...) inner {};
29 // expected-error@-1 {{pack expansion contains parameter packs 'A' and 'B' that have different lengths (1 vs. 2)}}
30};
31outer<int>::inner<short, double> mismatched_packs; // expected-note {{in instantiation of}}
Peter Collingbourne0b64ba92011-10-23 20:07:52 +000032
Richard Smith5f838aa2013-02-01 08:25:07 +000033typedef char align_typedef alignas(8); // expected-error {{'alignas' attribute only applies to variables, data members and tag types}}
Richard Smithd03de6a2013-01-29 10:02:16 +000034template<typename T> using align_alias_template = align_typedef alignas(8); // expected-error {{'alignas' attribute cannot be applied to types}}
Richard Smith3e4c6c42011-05-05 21:57:07 +000035
Richard Smitha0109e22013-01-29 10:18:18 +000036static_assert(alignof(align_big) == alignof(int), "k's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
37static_assert(alignof(align_small) == 1, "j's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
38static_assert(alignof(align_multiple) == 8, "l's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
Sean Huntbbd37c62009-11-21 08:43:09 +000039static_assert(alignof(align_member) == 8, "quuux's alignment is wrong");
40static_assert(sizeof(align_member) == 8, "quuux's size is wrong");
Peter Collingbourne0661bd0c2011-10-23 17:07:16 +000041static_assert(alignof(align_class_template<8>) == 8, "template's alignment is wrong");
42static_assert(alignof(align_class_template<16>) == 16, "template's alignment is wrong");
Richard Smithf6565a92013-02-22 08:32:16 +000043static_assert(alignof(align_class_temp_pack_type<short, int, long>) == alignof(long), "template's alignment is wrong");
44static_assert(alignof(align_class_temp_pack_expr<8, 16, 32>) == 32, "template's alignment is wrong");
45static_assert(alignof(outer<int,char>::inner<double,short>) == alignof(int) * alignof(double), "template's alignment is wrong");
Richard Smith7132be12013-03-18 23:37:25 +000046
47static_assert(alignof(int(int)) >= 1, "alignof(function) not positive"); // expected-warning{{invalid application of 'alignof' to a function type}}