| 1 |
// RUN: %clang_cc1 -fsyntax-only -fcxx-exceptions -verify -pedantic -std=c++11 %s |
| 2 |
|
| 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); // expected-error {{requested alignment is less than minimum}} |
| 6 |
int align_multiple alignas(1) alignas(8) alignas(1); |
| 7 |
alignas(4) int align_before; |
| 8 |
|
| 9 |
struct align_member { |
| 10 |
int member alignas(8); |
| 11 |
int bitfield alignas(1) : 1; // expected-error {{}} |
| 12 |
}; |
| 13 |
|
| 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}} expected-warning {{deprecated}} |
| 16 |
try { |
| 17 |
} catch (alignas(4) int n) { // expected-error {{'alignas' attribute cannot be applied to a 'catch' variable}} |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
template <unsigned A> struct alignas(A) align_class_template {}; |
| 23 |
|
| 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}} |
| 32 |
|
| 33 |
typedef char align_typedef alignas(8); // expected-error {{'alignas' attribute only applies to variables, data members and tag types}} |
| 34 |
template<typename T> using align_alias_template = align_typedef alignas(8); // expected-error {{'alignas' attribute cannot be applied to types}} |
| 35 |
|
| 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}} |
| 39 |
static_assert(alignof(align_member) == 8, "quuux's alignment is wrong"); |
| 40 |
static_assert(sizeof(align_member) == 8, "quuux's size is wrong"); |
| 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"); |
| 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"); |
| 46 |
|
| 47 |
static_assert(alignof(int(int)) >= 1, "alignof(function) not positive"); // expected-error{{invalid application of 'alignof' to a function type}} |
| 48 |
|
| 49 |
[[__carries_dependency__]] |
| 50 |
void func(void); |
| 51 |
|
| 52 |
alignas(4) auto PR19252 = 0; |
| 53 |
|
| 54 |
// Check the diagnostic message |
| 55 |
class alignas(void) AlignasVoid {}; // expected-error {{invalid application of 'alignas' to an incomplete type 'void'}} |
| 56 |
|
| 57 |
namespace GH108819 { |
| 58 |
void a([[maybe_unused]] void) {} // expected-warning {{attribute 'maybe_unused' cannot be applied to a 'void' parameter}}\ |
| 59 |
// expected-warning {{use of the 'maybe_unused' attribute is a C++17 extension}} |
| 60 |
void b([[deprecated, maybe_unused]] void) {} // expected-warning {{attribute 'deprecated' cannot be applied to a 'void' parameter}} \ |
| 61 |
// expected-warning {{attribute 'maybe_unused' cannot be applied to a 'void' parameter}} \ |
| 62 |
// expected-warning {{use of the 'deprecated' attribute is a C++14 extension}} \ |
| 63 |
// expected-warning {{use of the 'maybe_unused' attribute is a C++17 extension}} |
| 64 |
void c([[clang::lifetimebound]] void) {} // expected-warning {{attribute 'clang::lifetimebound' cannot be applied to a 'void' parameter}} |
| 65 |
void d([[clang::annotate("a", "b", 1)]] void) {} // expected-warning {{attribute 'clang::annotate' cannot be applied to a 'void' parameter}} |
| 66 |
|
| 67 |
struct S { |
| 68 |
void e([[maybe_unused]] void) {} // expected-warning {{attribute 'maybe_unused' cannot be applied to a 'void' parameter}} \ |
| 69 |
// expected-warning {{use of the 'maybe_unused' attribute is a C++17 extension}} |
| 70 |
}; |
| 71 |
|
| 72 |
template <typename T> |
| 73 |
void f([[maybe_unused]] void) {} // expected-warning {{attribute 'maybe_unused' cannot be applied to a 'void' parameter}} \ |
| 74 |
// expected-warning {{use of the 'maybe_unused' attribute is a C++17 extension}} |
| 75 |
|
| 76 |
auto g = []([[maybe_unused]] void) { }; // expected-warning {{attribute 'maybe_unused' cannot be applied to a 'void' parameter}} \ |
| 77 |
// expected-warning {{use of the 'maybe_unused' attribute is a C++17 extension}} |
| 78 |
} |