Richard Smith | 762bb9d | 2011-10-13 22:29:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -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); |
| 5 | int align_small alignas(1); // FIXME: this should be rejected |
| 6 | int align_multiple alignas(1) alignas(8) alignas(1); |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 7 | |
| 8 | struct align_member { |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 9 | int member alignas(8); |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 10 | }; |
| 11 | |
Eli Friedman | fc038e9 | 2011-12-17 00:36:09 +0000 | [diff] [blame] | 12 | template <unsigned A> struct alignas(A) align_class_template {}; |
Peter Collingbourne | 0661bd0c | 2011-10-23 17:07:16 +0000 | [diff] [blame] | 13 | |
Peter Collingbourne | 0b64ba9 | 2011-10-23 20:07:52 +0000 | [diff] [blame] | 14 | // FIXME: these should not error |
| 15 | template <typename... T> alignas(T...) struct align_class_temp_pack_type {}; // expected-error{{pack expansions in alignment specifiers are not supported yet}} |
| 16 | template <unsigned... A> alignas(A...) struct align_class_temp_pack_expr {}; // expected-error{{pack expansions in alignment specifiers are not supported yet}} |
| 17 | |
Peter Collingbourne | 82d0b0a | 2011-09-29 18:04:28 +0000 | [diff] [blame] | 18 | typedef char align_typedef alignas(8); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 19 | template<typename T> using align_alias_template = align_typedef; |
| 20 | |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 21 | static_assert(alignof(align_big) == alignof(int), "k's alignment is wrong"); |
John McCall | 4081a5c | 2010-10-08 18:24:19 +0000 | [diff] [blame] | 22 | static_assert(alignof(align_small) == 1, "j's alignment is wrong"); |
Sean Hunt | bbd37c6 | 2009-11-21 08:43:09 +0000 | [diff] [blame] | 23 | static_assert(alignof(align_multiple) == 8, "l's alignment is wrong"); |
| 24 | static_assert(alignof(align_member) == 8, "quuux's alignment is wrong"); |
| 25 | static_assert(sizeof(align_member) == 8, "quuux's size is wrong"); |
Richard Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 26 | static_assert(alignof(align_typedef) == 8, "typedef's alignment is wrong"); |
Peter Collingbourne | 0661bd0c | 2011-10-23 17:07:16 +0000 | [diff] [blame] | 27 | static_assert(alignof(align_class_template<8>) == 8, "template's alignment is wrong"); |
| 28 | static_assert(alignof(align_class_template<16>) == 16, "template's alignment is wrong"); |
Peter Collingbourne | 0b64ba9 | 2011-10-23 20:07:52 +0000 | [diff] [blame] | 29 | // 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 Smith | 3e4c6c4 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 32 | static_assert(alignof(align_alias_template<int>) == 8, "alias template's alignment is wrong"); |