blob: def83a94ea2b8e58c913b11f6e13cab87b9c0f63 [file] [log] [blame]
NAKAMURA Takumife1d5942013-01-14 13:16:02 +00001// RUN: %clang -cc1 -triple x86_64-unknown-unknown -std=c++11 -verify %s
Richard Smithd6e7fae2013-01-14 08:57:42 +00002
3// Error cases.
4
5[[gnu::this_attribute_does_not_exist]] int unknown_attr;
6// expected-warning@-1 {{unknown attribute 'this_attribute_does_not_exist' ignored}}
7int [[gnu::unused]] attr_on_type;
Richard Smithd03de6a2013-01-29 10:02:16 +00008// expected-error@-1 {{'unused' attribute cannot be applied to types}}
Richard Smithd6e7fae2013-01-14 08:57:42 +00009int *[[gnu::unused]] attr_on_ptr;
10// expected-warning@-1 {{attribute 'unused' ignored, because it cannot be applied to a type}}
11
12// Valid cases.
13
14void alias1() {}
15void alias2 [[gnu::alias("_Z6alias1v")]] ();
16
17[[gnu::aligned(8)]] int aligned;
18void aligned_fn [[gnu::aligned(32)]] ();
19struct [[gnu::aligned(8)]] aligned_struct {};
20
21[[gnu::malloc, gnu::alloc_size(1,2)]] void *alloc_size(int a, int b);
22
23void always_inline [[gnu::always_inline]] ();
24
25__thread int tls_model [[gnu::tls_model("local-exec")]];
26
27void cleanup(int *p) {
28 int n [[gnu::cleanup(cleanup)]];
29}
30
31void deprecated1 [[gnu::deprecated]] (); // expected-note {{here}}
32[[gnu::deprecated("custom message")]] void deprecated2(); // expected-note {{here}}
33void deprecated3() {
34 deprecated1(); // expected-warning {{deprecated}}
35 deprecated2(); // expected-warning {{custom message}}
36}
37
38[[gnu::naked(1,2,3)]] void naked(); // expected-error {{takes no arguments}}
39
40void nonnull [[gnu::nonnull]] (); // expected-warning {{applied to function with no pointer arguments}}
41
Richard Smith5c521662013-01-15 02:48:13 +000042// [[gnu::noreturn]] appertains to a declaration, and marks the innermost
43// function declarator in that declaration as being noreturn.
Richard Smithd6e7fae2013-01-14 08:57:42 +000044int noreturn [[gnu::noreturn]]; // expected-warning {{'noreturn' only applies to function types}}
Richard Smith5c521662013-01-15 02:48:13 +000045int noreturn_fn_1();
46int noreturn_fn_2() [[gnu::noreturn]]; // expected-warning {{cannot be applied to a type}}
47int noreturn_fn_3 [[gnu::noreturn]] ();
48[[gnu::noreturn]] int noreturn_fn_4();
49int (*noreturn_fn_ptr_1 [[gnu::noreturn]])() = &noreturn_fn_1; // expected-error {{cannot initialize}}
50int (*noreturn_fn_ptr_2 [[gnu::noreturn]])() = &noreturn_fn_3;
51[[gnu::noreturn]] int (*noreturn_fn_ptr_3)() = &noreturn_fn_1; // expected-error {{cannot initialize}}
52[[gnu::noreturn]] int (*noreturn_fn_ptr_4)() = &noreturn_fn_3;
Richard Smithd6e7fae2013-01-14 08:57:42 +000053
54struct [[gnu::packed]] packed { char c; int n; };
55static_assert(sizeof(packed) == sizeof(char) + sizeof(int), "not packed");