2013-03-19 07:37:25 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -pedantic -std=c++11 %s
|
2009-11-21 16:43:09 +08:00
|
|
|
|
2011-09-30 02:04:28 +08:00
|
|
|
int align_illegal alignas(3); //expected-error {{requested alignment is not a power of 2}}
|
|
|
|
char align_big alignas(int);
|
2013-02-01 16:12:08 +08:00
|
|
|
int align_small alignas(1); // expected-error {{requested alignment is less than minimum}}
|
2011-09-30 02:04:28 +08:00
|
|
|
int align_multiple alignas(1) alignas(8) alignas(1);
|
2013-01-29 17:02:09 +08:00
|
|
|
alignas(4) int align_before;
|
2009-11-21 16:43:09 +08:00
|
|
|
|
|
|
|
struct align_member {
|
2011-09-30 02:04:28 +08:00
|
|
|
int member alignas(8);
|
2013-01-29 17:02:09 +08:00
|
|
|
int bitfield alignas(1) : 1; // expected-error {{}}
|
2009-11-21 16:43:09 +08:00
|
|
|
};
|
|
|
|
|
2013-01-29 17:02:09 +08:00
|
|
|
void f(alignas(1) char c) { // expected-error {{'alignas' attribute cannot be applied to a function parameter}}
|
|
|
|
alignas(1) register char k; // expected-error {{'alignas' attribute cannot be applied to a variable with 'register' storage class}}
|
|
|
|
try {
|
|
|
|
} catch (alignas(4) int n) { // expected-error {{'alignas' attribute cannot be applied to a 'catch' variable}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-17 08:36:09 +08:00
|
|
|
template <unsigned A> struct alignas(A) align_class_template {};
|
2011-10-24 01:07:16 +08:00
|
|
|
|
2013-02-22 16:32:16 +08:00
|
|
|
template <typename... T> struct alignas(T...) align_class_temp_pack_type {};
|
|
|
|
template <unsigned... A> struct alignas(A...) align_class_temp_pack_expr {};
|
|
|
|
struct alignas(int...) alignas_expansion_no_packs {}; // expected-error {{pack expansion does not contain any unexpanded parameter packs}}
|
|
|
|
template <typename... A> struct outer {
|
|
|
|
template <typename... B> struct alignas(alignof(A) * alignof(B)...) inner {};
|
|
|
|
// expected-error@-1 {{pack expansion contains parameter packs 'A' and 'B' that have different lengths (1 vs. 2)}}
|
|
|
|
};
|
|
|
|
outer<int>::inner<short, double> mismatched_packs; // expected-note {{in instantiation of}}
|
2011-10-24 04:07:52 +08:00
|
|
|
|
2013-02-01 16:25:07 +08:00
|
|
|
typedef char align_typedef alignas(8); // expected-error {{'alignas' attribute only applies to variables, data members and tag types}}
|
2013-01-29 18:02:16 +08:00
|
|
|
template<typename T> using align_alias_template = align_typedef alignas(8); // expected-error {{'alignas' attribute cannot be applied to types}}
|
2011-05-06 05:57:07 +08:00
|
|
|
|
2013-01-29 18:18:18 +08:00
|
|
|
static_assert(alignof(align_big) == alignof(int), "k's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
|
|
|
|
static_assert(alignof(align_small) == 1, "j's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
|
|
|
|
static_assert(alignof(align_multiple) == 8, "l's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
|
2009-11-21 16:43:09 +08:00
|
|
|
static_assert(alignof(align_member) == 8, "quuux's alignment is wrong");
|
|
|
|
static_assert(sizeof(align_member) == 8, "quuux's size is wrong");
|
2011-10-24 01:07:16 +08:00
|
|
|
static_assert(alignof(align_class_template<8>) == 8, "template's alignment is wrong");
|
|
|
|
static_assert(alignof(align_class_template<16>) == 16, "template's alignment is wrong");
|
2013-02-22 16:32:16 +08:00
|
|
|
static_assert(alignof(align_class_temp_pack_type<short, int, long>) == alignof(long), "template's alignment is wrong");
|
|
|
|
static_assert(alignof(align_class_temp_pack_expr<8, 16, 32>) == 32, "template's alignment is wrong");
|
|
|
|
static_assert(alignof(outer<int,char>::inner<double,short>) == alignof(int) * alignof(double), "template's alignment is wrong");
|
2013-03-19 07:37:25 +08:00
|
|
|
|
|
|
|
static_assert(alignof(int(int)) >= 1, "alignof(function) not positive"); // expected-warning{{invalid application of 'alignof' to a function type}}
|