attr-cxx0x.cpp revision a0109e284457c996d4eb8f231e01dda303d1a345
1// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -std=c++11 %s 2 3int 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); 7alignas(4) int align_before; 8 9struct align_member { 10 int member alignas(8); 11 int bitfield alignas(1) : 1; // expected-error {{}} 12}; 13 14void 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 22template <unsigned A> struct alignas(A) align_class_template {}; 23 24// FIXME: these should not error 25template <typename... T> alignas(T...) struct align_class_temp_pack_type {}; // expected-error{{pack expansions in alignment specifiers are not supported yet}} 26template <unsigned... A> alignas(A...) struct align_class_temp_pack_expr {}; // expected-error{{pack expansions in alignment specifiers are not supported yet}} 27 28typedef char align_typedef alignas(8); // expected-error {{'alignas' attribute only applies to variables, functions and tag types}} 29template<typename T> using align_alias_template = align_typedef alignas(8); // expected-error {{'alignas' attribute cannot be applied to types}} 30 31static_assert(alignof(align_big) == alignof(int), "k's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}} 32static_assert(alignof(align_small) == 1, "j's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}} 33static_assert(alignof(align_multiple) == 8, "l's alignment is wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}} 34static_assert(alignof(align_member) == 8, "quuux's alignment is wrong"); 35static_assert(sizeof(align_member) == 8, "quuux's size is wrong"); 36static_assert(alignof(align_class_template<8>) == 8, "template's alignment is wrong"); 37static_assert(alignof(align_class_template<16>) == 16, "template's alignment is wrong"); 38// FIXME: enable these tests 39// static_assert(alignof(align_class_temp_pack_type<short, int, long>) == alignof(long), "template's alignment is wrong"); 40// static_assert(alignof(align_class_temp_pack_expr<8, 16, 32>) == 32, "template's alignment is wrong"); 41