Alp Toker | 93c33c1 | 2013-10-28 23:47:09 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++11 -verify %s |
Richard Smith | b5b5320 | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 2 | |
| 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}} |
| 7 | int [[gnu::unused]] attr_on_type; |
Richard Smith | 810ad3e | 2013-01-29 10:02:16 +0000 | [diff] [blame] | 8 | // expected-error@-1 {{'unused' attribute cannot be applied to types}} |
Richard Smith | b5b5320 | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 9 | int *[[gnu::unused]] attr_on_ptr; |
| 10 | // expected-warning@-1 {{attribute 'unused' ignored, because it cannot be applied to a type}} |
Alexander Musman | 94f14d9 | 2015-05-29 11:24:32 +0000 | [diff] [blame] | 11 | [[gnu::fastcall]] void pr17424_1(); |
| 12 | // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}} |
| 13 | [[gnu::fastcall]] [[gnu::stdcall]] void pr17424_2(); |
| 14 | // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}} |
| 15 | // expected-warning@-2 {{calling convention 'stdcall' ignored for this target}} |
| 16 | [[gnu::fastcall]] __stdcall void pr17424_3(); |
| 17 | // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}} |
| 18 | // expected-warning@-2 {{calling convention '__stdcall' ignored for this target}} |
| 19 | [[gnu::fastcall]] void pr17424_4() [[gnu::stdcall]]; |
| 20 | // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}} |
| 21 | // expected-warning@-2 {{attribute 'stdcall' ignored, because it cannot be applied to a type}} |
John McCall | 3b5a8f5 | 2016-03-03 00:10:03 +0000 | [diff] [blame] | 22 | // expected-warning@-3 {{calling convention 'stdcall' ignored for this target}} |
Alexander Musman | 94f14d9 | 2015-05-29 11:24:32 +0000 | [diff] [blame] | 23 | void pr17424_5 [[gnu::fastcall]](); |
| 24 | // expected-warning@-1 {{calling convention 'fastcall' ignored for this target}} |
Richard Smith | b5b5320 | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 25 | |
| 26 | // Valid cases. |
| 27 | |
Rafael Espindola | 4517d59 | 2013-10-21 18:24:30 +0000 | [diff] [blame] | 28 | void aliasb [[gnu::alias("_Z6alias1v")]] (); |
Richard Smith | b5b5320 | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 29 | void alias1() {} |
Rafael Espindola | 4517d59 | 2013-10-21 18:24:30 +0000 | [diff] [blame] | 30 | void aliasa [[gnu::alias("_Z6alias1v")]] (); |
Richard Smith | b5b5320 | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 31 | |
David Majnemer | e9624ed | 2015-02-08 10:55:14 +0000 | [diff] [blame] | 32 | extern struct PR22493Ty { |
| 33 | } PR22493 [[gnu::alias("_ZN7pcrecpp2RE6no_argE")]]; |
| 34 | |
Richard Smith | b5b5320 | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 35 | [[gnu::aligned(8)]] int aligned; |
| 36 | void aligned_fn [[gnu::aligned(32)]] (); |
| 37 | struct [[gnu::aligned(8)]] aligned_struct {}; |
| 38 | |
Richard Smith | b5b5320 | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 39 | void always_inline [[gnu::always_inline]] (); |
| 40 | |
| 41 | __thread int tls_model [[gnu::tls_model("local-exec")]]; |
| 42 | |
| 43 | void cleanup(int *p) { |
| 44 | int n [[gnu::cleanup(cleanup)]]; |
| 45 | } |
| 46 | |
| 47 | void deprecated1 [[gnu::deprecated]] (); // expected-note {{here}} |
| 48 | [[gnu::deprecated("custom message")]] void deprecated2(); // expected-note {{here}} |
| 49 | void deprecated3() { |
| 50 | deprecated1(); // expected-warning {{deprecated}} |
| 51 | deprecated2(); // expected-warning {{custom message}} |
| 52 | } |
| 53 | |
| 54 | [[gnu::naked(1,2,3)]] void naked(); // expected-error {{takes no arguments}} |
| 55 | |
| 56 | void nonnull [[gnu::nonnull]] (); // expected-warning {{applied to function with no pointer arguments}} |
| 57 | |
Richard Smith | 0faa2b1 | 2013-01-15 02:48:13 +0000 | [diff] [blame] | 58 | // [[gnu::noreturn]] appertains to a declaration, and marks the innermost |
| 59 | // function declarator in that declaration as being noreturn. |
Richard Smith | b5b5320 | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 60 | int noreturn [[gnu::noreturn]]; // expected-warning {{'noreturn' only applies to function types}} |
Richard Smith | 0faa2b1 | 2013-01-15 02:48:13 +0000 | [diff] [blame] | 61 | int noreturn_fn_1(); |
| 62 | int noreturn_fn_2() [[gnu::noreturn]]; // expected-warning {{cannot be applied to a type}} |
| 63 | int noreturn_fn_3 [[gnu::noreturn]] (); |
| 64 | [[gnu::noreturn]] int noreturn_fn_4(); |
| 65 | int (*noreturn_fn_ptr_1 [[gnu::noreturn]])() = &noreturn_fn_1; // expected-error {{cannot initialize}} |
| 66 | int (*noreturn_fn_ptr_2 [[gnu::noreturn]])() = &noreturn_fn_3; |
| 67 | [[gnu::noreturn]] int (*noreturn_fn_ptr_3)() = &noreturn_fn_1; // expected-error {{cannot initialize}} |
| 68 | [[gnu::noreturn]] int (*noreturn_fn_ptr_4)() = &noreturn_fn_3; |
Richard Smith | b5b5320 | 2013-01-14 08:57:42 +0000 | [diff] [blame] | 69 | |
| 70 | struct [[gnu::packed]] packed { char c; int n; }; |
| 71 | static_assert(sizeof(packed) == sizeof(char) + sizeof(int), "not packed"); |