Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc %s -verify -fsyntax-only |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 2 | |
| 3 | int f() __attribute__((deprecated)); |
| 4 | void g() __attribute__((deprecated)); |
| 5 | void g(); |
| 6 | |
Anders Carlsson | b235caa | 2009-02-13 08:22:04 +0000 | [diff] [blame] | 7 | void z() __attribute__((bogusattr)); // expected-warning {{'bogusattr' attribute ignored}} |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 8 | |
| 9 | extern int var __attribute__((deprecated)); |
| 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 |
| 22 | extern int var; |
| 23 | int w() { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 24 | return var; // expected-warning {{'var' is deprecated}} |
Chris Lattner | ddee423 | 2008-03-03 03:28:21 +0000 | [diff] [blame] | 25 | } |
Chris Lattner | 4238254 | 2009-02-14 08:27:44 +0000 | [diff] [blame] | 26 | |
| 27 | int old_fn() __attribute__ ((deprecated)); |
| 28 | int old_fn(); |
| 29 | int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}} |
| 30 | |
| 31 | int old_fn() { |
Chris Lattner | 61a0f17 | 2009-02-15 01:38:09 +0000 | [diff] [blame] | 32 | return old_fn()+1; // no warning, deprecated functions can use deprecated symbols. |
Chris Lattner | 4238254 | 2009-02-14 08:27:44 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Chris Lattner | cfdff38 | 2009-02-16 17:07:21 +0000 | [diff] [blame] | 35 | |
| 36 | struct foo { |
| 37 | int x __attribute__((deprecated)); |
| 38 | }; |
| 39 | |
| 40 | void test1(struct foo *F) { |
| 41 | ++F->x; // expected-warning {{'x' is deprecated}} |
| 42 | } |
Chris Lattner | 553905d | 2009-02-16 17:19:12 +0000 | [diff] [blame] | 43 | |
Chris Lattner | 22bd905 | 2009-02-16 22:07:16 +0000 | [diff] [blame] | 44 | typedef struct foo foo_dep __attribute__((deprecated)); |
| 45 | foo_dep *test2; // expected-warning {{'foo_dep' is deprecated}} |
Chris Lattner | d451f83 | 2009-10-25 22:21:57 +0000 | [diff] [blame] | 46 | |
| 47 | struct bar_dep __attribute__((deprecated, |
| 48 | invalid_attribute)); // expected-warning {{'invalid_attribute' attribute ignored}} |
| 49 | |
| 50 | struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}} |
| 51 | |
Chris Lattner | 5233826 | 2009-10-25 22:31:57 +0000 | [diff] [blame] | 52 | |
| 53 | // These should not warn because the actually declaration itself is deprecated. |
| 54 | // rdar://6756623 |
| 55 | foo_dep *test4 __attribute__((deprecated)); |
| 56 | struct bar_dep *test5 __attribute__((deprecated)); |
| 57 | |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame^] | 58 | typedef foo_dep test6(struct bar_dep*); // expected-warning {{'foo_dep' is deprecated}} \ |
| 59 | // expected-warning {{'bar_dep' is deprecated}} |
| 60 | typedef foo_dep test7(struct bar_dep*) __attribute__((deprecated)); |
| 61 | |
| 62 | int test8(char *p) { |
| 63 | p += sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}} |
| 64 | |
| 65 | foo_dep *ptr; // expected-warning {{'foo_dep' is deprecated}} |
| 66 | ptr = (foo_dep*) p; // expected-warning {{'foo_dep' is deprecated}} |
| 67 | |
| 68 | int func(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}} |
| 69 | return func(ptr); |
| 70 | } |
| 71 | |
| 72 | foo_dep *test9(void) __attribute__((deprecated)); |
| 73 | foo_dep *test9(void) { |
| 74 | void* myalloc(unsigned long); |
| 75 | |
| 76 | foo_dep *ptr |
| 77 | = (foo_dep*) |
| 78 | myalloc(sizeof(foo_dep)); |
| 79 | return ptr; |
| 80 | } |
| 81 | |
| 82 | void test10(void) __attribute__((deprecated)); |
| 83 | void test10(void) { |
| 84 | if (sizeof(foo_dep) == sizeof(void*)) { |
| 85 | } |
| 86 | foo_dep *localfunc(void); |
| 87 | foo_dep localvar; |
| 88 | } |
| 89 | |
| 90 | char test11[sizeof(foo_dep)] __attribute__((deprecated)); |
| 91 | char test12[sizeof(foo_dep)]; // expected-warning {{'foo_dep' is deprecated}} |
| 92 | |
| 93 | int test13(foo_dep *foo) __attribute__((deprecated)); |
| 94 | int test14(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}} |
| 95 | |
| 96 | unsigned long test15 = sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}} |
| 97 | unsigned long test16 __attribute__((deprecated)) |
| 98 | = sizeof(foo_dep); |
| 99 | |
| 100 | foo_dep test17, // expected-warning {{'foo_dep' is deprecated}} |
| 101 | test18 __attribute__((deprecated)), |
| 102 | test19; |