Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -verify -fsyntax-only |
Erich Keane | a32910d | 2017-03-23 18:51:54 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 %s -std=c89 -verify -fsyntax-only |
| 3 | // RUN: %clang_cc1 %s -std=c99 -verify -fsyntax-only |
Chris Lattner | 8496639 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 4 | |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 5 | int f() __attribute__((deprecated)); // expected-note 2 {{'f' has been explicitly marked deprecated here}} |
Erich Keane | a32910d | 2017-03-23 18:51:54 +0000 | [diff] [blame] | 6 | void g() __attribute__((deprecated));// expected-note {{'g' has been explicitly marked deprecated here}} |
| 7 | void g(); |
Chris Lattner | 8496639 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 8 | |
Erich Keane | a32910d | 2017-03-23 18:51:54 +0000 | [diff] [blame] | 9 | extern int var __attribute__((deprecated)); // expected-note 2 {{'var' has been explicitly marked deprecated here}} |
Chris Lattner | 8496639 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 10 | |
| 11 | int a() { |
| 12 | int (*ptr)() = f; // expected-warning {{'f' is deprecated}} |
| 13 | f(); // expected-warning {{'f' is deprecated}} |
| 14 | |
| 15 | // test if attributes propagate to functions |
| 16 | g(); // expected-warning {{'g' is deprecated}} |
| 17 | |
| 18 | return var; // expected-warning {{'var' is deprecated}} |
| 19 | } |
| 20 | |
| 21 | // test if attributes propagate to variables |
Erich Keane | a32910d | 2017-03-23 18:51:54 +0000 | [diff] [blame] | 22 | extern int var; |
Chris Lattner | 8496639 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 23 | int w() { |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 24 | return var; // expected-warning {{'var' is deprecated}} |
Chris Lattner | 8496639 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 25 | } |
Chris Lattner | aff3014 | 2009-02-14 08:27:44 +0000 | [diff] [blame] | 26 | |
Erich Keane | a32910d | 2017-03-23 18:51:54 +0000 | [diff] [blame] | 27 | int old_fn() __attribute__ ((deprecated));// expected-note {{'old_fn' has been explicitly marked deprecated here}} |
| 28 | int old_fn(); |
Chris Lattner | aff3014 | 2009-02-14 08:27:44 +0000 | [diff] [blame] | 29 | int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}} |
| 30 | |
| 31 | int old_fn() { |
Chris Lattner | 4c6ea86 | 2009-02-15 01:38:09 +0000 | [diff] [blame] | 32 | return old_fn()+1; // no warning, deprecated functions can use deprecated symbols. |
Chris Lattner | aff3014 | 2009-02-14 08:27:44 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Chris Lattner | ee4b523 | 2009-02-16 17:07:21 +0000 | [diff] [blame] | 35 | |
| 36 | struct foo { |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 37 | int x __attribute__((deprecated)); // expected-note 3 {{'x' has been explicitly marked deprecated here}} |
Chris Lattner | ee4b523 | 2009-02-16 17:07:21 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | void test1(struct foo *F) { |
| 41 | ++F->x; // expected-warning {{'x' is deprecated}} |
Douglas Gregor | a82064c | 2011-06-29 21:51:31 +0000 | [diff] [blame] | 42 | struct foo f1 = { .x = 17 }; // expected-warning {{'x' is deprecated}} |
| 43 | struct foo f2 = { 17 }; // expected-warning {{'x' is deprecated}} |
Chris Lattner | ee4b523 | 2009-02-16 17:07:21 +0000 | [diff] [blame] | 44 | } |
Chris Lattner | 50afe31 | 2009-02-16 17:19:12 +0000 | [diff] [blame] | 45 | |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 46 | typedef struct foo foo_dep __attribute__((deprecated)); // expected-note 12 {{'foo_dep' has been explicitly marked deprecated here}} |
Chris Lattner | a377833 | 2009-02-16 22:07:16 +0000 | [diff] [blame] | 47 | foo_dep *test2; // expected-warning {{'foo_dep' is deprecated}} |
Chris Lattner | ecf328e | 2009-10-25 22:21:57 +0000 | [diff] [blame] | 48 | |
Erich Keane | a32910d | 2017-03-23 18:51:54 +0000 | [diff] [blame] | 49 | struct __attribute__((deprecated, // expected-note 2 {{'bar_dep' has been explicitly marked deprecated here}} |
| 50 | invalid_attribute)) bar_dep ; // expected-warning {{unknown attribute 'invalid_attribute' ignored}} |
Chris Lattner | ecf328e | 2009-10-25 22:21:57 +0000 | [diff] [blame] | 51 | |
| 52 | struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}} |
| 53 | |
Chris Lattner | b7df3c6 | 2009-10-25 22:31:57 +0000 | [diff] [blame] | 54 | |
| 55 | // These should not warn because the actually declaration itself is deprecated. |
| 56 | // rdar://6756623 |
| 57 | foo_dep *test4 __attribute__((deprecated)); |
| 58 | struct bar_dep *test5 __attribute__((deprecated)); |
| 59 | |
John McCall | 28a6aea | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 60 | typedef foo_dep test6(struct bar_dep*); // expected-warning {{'foo_dep' is deprecated}} \ |
| 61 | // expected-warning {{'bar_dep' is deprecated}} |
| 62 | typedef foo_dep test7(struct bar_dep*) __attribute__((deprecated)); |
| 63 | |
| 64 | int test8(char *p) { |
| 65 | p += sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}} |
| 66 | |
| 67 | foo_dep *ptr; // expected-warning {{'foo_dep' is deprecated}} |
| 68 | ptr = (foo_dep*) p; // expected-warning {{'foo_dep' is deprecated}} |
| 69 | |
| 70 | int func(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}} |
| 71 | return func(ptr); |
| 72 | } |
| 73 | |
| 74 | foo_dep *test9(void) __attribute__((deprecated)); |
| 75 | foo_dep *test9(void) { |
| 76 | void* myalloc(unsigned long); |
| 77 | |
| 78 | foo_dep *ptr |
| 79 | = (foo_dep*) |
| 80 | myalloc(sizeof(foo_dep)); |
| 81 | return ptr; |
| 82 | } |
| 83 | |
| 84 | void test10(void) __attribute__((deprecated)); |
| 85 | void test10(void) { |
| 86 | if (sizeof(foo_dep) == sizeof(void*)) { |
| 87 | } |
| 88 | foo_dep *localfunc(void); |
| 89 | foo_dep localvar; |
| 90 | } |
| 91 | |
| 92 | char test11[sizeof(foo_dep)] __attribute__((deprecated)); |
| 93 | char test12[sizeof(foo_dep)]; // expected-warning {{'foo_dep' is deprecated}} |
| 94 | |
| 95 | int test13(foo_dep *foo) __attribute__((deprecated)); |
| 96 | int test14(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}} |
| 97 | |
| 98 | unsigned long test15 = sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}} |
| 99 | unsigned long test16 __attribute__((deprecated)) |
| 100 | = sizeof(foo_dep); |
| 101 | |
| 102 | foo_dep test17, // expected-warning {{'foo_dep' is deprecated}} |
| 103 | test18 __attribute__((deprecated)), |
| 104 | test19; |
John McCall | 811a0f5 | 2010-10-22 23:36:17 +0000 | [diff] [blame] | 105 | |
| 106 | // rdar://problem/8518751 |
Erik Pilkington | 4042f3c | 2017-07-05 17:08:56 +0000 | [diff] [blame] | 107 | enum __attribute__((deprecated)) Test20 { // expected-note 2 {{'Test20' has been explicitly marked deprecated here}} |
Ted Kremenek | b79ee57 | 2013-12-18 23:30:06 +0000 | [diff] [blame] | 108 | test20_a __attribute__((deprecated)), // expected-note {{'test20_a' has been explicitly marked deprecated here}} |
Erik Pilkington | 4042f3c | 2017-07-05 17:08:56 +0000 | [diff] [blame] | 109 | test20_b |
John McCall | 811a0f5 | 2010-10-22 23:36:17 +0000 | [diff] [blame] | 110 | }; |
| 111 | void test20() { |
| 112 | enum Test20 f; // expected-warning {{'Test20' is deprecated}} |
| 113 | f = test20_a; // expected-warning {{'test20_a' is deprecated}} |
Fariborz Jahanian | 25d09c2 | 2011-11-28 19:45:58 +0000 | [diff] [blame] | 114 | f = test20_b; // expected-warning {{'test20_b' is deprecated}} |
John McCall | 811a0f5 | 2010-10-22 23:36:17 +0000 | [diff] [blame] | 115 | } |
John McCall | f71b453 | 2010-11-08 19:48:17 +0000 | [diff] [blame] | 116 | |
| 117 | char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1]; |
Eli Friedman | 89b1f2c | 2012-08-08 23:04:35 +0000 | [diff] [blame] | 118 | |
| 119 | struct test22 { |
| 120 | foo_dep a __attribute((deprecated)); |
| 121 | foo_dep b; // expected-warning {{'foo_dep' is deprecated}} |
| 122 | foo_dep c, d __attribute((deprecated)); // expected-warning {{'foo_dep' is deprecated}} |
| 123 | __attribute((deprecated)) foo_dep e, f; |
| 124 | }; |
Eli Friedman | e7b8aa9 | 2013-07-16 02:07:49 +0000 | [diff] [blame] | 125 | |
Erich Keane | a32910d | 2017-03-23 18:51:54 +0000 | [diff] [blame] | 126 | typedef int test23_ty __attribute((deprecated)); |
Sunil Srivastava | bf01080 | 2016-04-27 19:53:03 +0000 | [diff] [blame] | 127 | // Redefining a typedef is a C11 feature. |
| 128 | #if __STDC_VERSION__ <= 199901L |
| 129 | // expected-note@-3 {{'test23_ty' has been explicitly marked deprecated here}} |
| 130 | #else |
Erich Keane | a32910d | 2017-03-23 18:51:54 +0000 | [diff] [blame] | 131 | // expected-note@-5 {{'test23_ty' has been explicitly marked deprecated here}} |
| 132 | typedef int test23_ty; |
Sunil Srivastava | bf01080 | 2016-04-27 19:53:03 +0000 | [diff] [blame] | 133 | #endif |
Eli Friedman | e7b8aa9 | 2013-07-16 02:07:49 +0000 | [diff] [blame] | 134 | test23_ty test23_v; // expected-warning {{'test23_ty' is deprecated}} |