Richard Smith | 7132be1 | 2013-03-18 23:37:25 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -pedantic -std=c++11 %s |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 2 | |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 3 | int align_illegal alignas(3); //expected-error {{requested alignment is not a power of 2}} |
| 4 | char align_big alignas(int); |
Richard Smith | be507b6 | 2013-02-01 08:12:08 +0000 | [diff] [blame] | 5 | int align_small alignas(1); // expected-error {{requested alignment is less than minimum}} |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 6 | int align_multiple alignas(1) alignas(8) alignas(1); |
Richard Smith | 4cd81c5 | 2013-01-29 09:02:09 +0000 | [diff] [blame] | 7 | alignas(4) int align_before; |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 8 | |
| 9 | struct align_member { |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 10 | int member alignas(8); |
Richard Smith | 4cd81c5 | 2013-01-29 09:02:09 +0000 | [diff] [blame] | 11 | int bitfield alignas(1) : 1; // expected-error {{}} |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 12 | }; |
| 13 | |
Richard Smith | 4cd81c5 | 2013-01-29 09:02:09 +0000 | [diff] [blame] | 14 | void 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 Friedman | fc038e9 | 2011-12-17 00:36:09 +0000 | [diff] [blame] | 22 | template <unsigned A> struct alignas(A) align_class_template {}; |
Peter Collingbourne | 0661bd0c | 2011-10-23 17:07:16 +0000 | [diff] [blame] | 23 | |
Richard Smith | f6565a9 | 2013-02-22 08:32:16 +0000 | [diff] [blame] | 24 | template <typename... T> struct alignas(T...) align_class_temp_pack_type {}; |
| 25 | template <unsigned... A> struct alignas(A...) align_class_temp_pack_expr {}; |
| 26 | struct alignas(int...) alignas_expansion_no_packs {}; // expected-error {{pack expansion does not contain any unexpanded parameter packs}} |
| 27 | template <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 | }; |
| 31 | outer<int>::inner<short, double> mismatched_packs; // expected-note {{in instantiation of}} |
Peter Collingbourne | 0b64ba9 | 2011-10-23 20:07:52 +0000 | [diff] [blame] | 32 | |
Richard Smith | 5f838aa | 2013-02-01 08:25:07 +0000 | [diff] [blame] | 33 | typedef char align_typedef alignas(8); // expected-error {{'alignas' attribute only applies to variables, data members and tag types}} |
Richard Smith | d03de6a | 2013-01-29 10:02:16 +0000 | [diff] [blame] | 34 | template<typename T> using align_alias_template = align_typedef alignas(8); // expected-error {{'alignas' attribute cannot be applied to types}} |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 35 | |
Richard Smith | a0109e2 | 2013-01-29 10:18:18 +0000 | [diff] [blame] | 36 | static_assert(alignof(align_big) == alignof(int), "k's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}} |
| 37 | static_assert(alignof(align_small) == 1, "j's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}} |
| 38 | static_assert(alignof(align_multiple) == 8, "l's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}} |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 39 | static_assert(alignof(align_member) == 8, "quuux's alignment is wrong"); |
| 40 | static_assert(sizeof(align_member) == 8, "quuux's size is wrong"); |
Peter Collingbourne | 0661bd0c | 2011-10-23 17:07:16 +0000 | [diff] [blame] | 41 | static_assert(alignof(align_class_template<8>) == 8, "template's alignment is wrong"); |
| 42 | static_assert(alignof(align_class_template<16>) == 16, "template's alignment is wrong"); |
Richard Smith | f6565a9 | 2013-02-22 08:32:16 +0000 | [diff] [blame] | 43 | static_assert(alignof(align_class_temp_pack_type<short, int, long>) == alignof(long), "template's alignment is wrong"); |
| 44 | static_assert(alignof(align_class_temp_pack_expr<8, 16, 32>) == 32, "template's alignment is wrong"); |
| 45 | static_assert(alignof(outer<int,char>::inner<double,short>) == alignof(int) * alignof(double), "template's alignment is wrong"); |
Richard Smith | 7132be1 | 2013-03-18 23:37:25 +0000 | [diff] [blame] | 46 | |
| 47 | static_assert(alignof(int(int)) >= 1, "alignof(function) not positive"); // expected-warning{{invalid application of 'alignof' to a function type}} |