1 // RUN: %clang_cc1 %s -verify -fsyntax-only 2 // RUN: %clang_cc1 %s -std=c89 -verify -fsyntax-only 3 // RUN: %clang_cc1 %s -std=c99 -verify -fsyntax-only 4 5 int f(void) __attribute__((deprecated)); // expected-note 2 {{'f' has been explicitly marked deprecated here}} 6 void g(void) __attribute__((deprecated));// expected-note {{'g' has been explicitly marked deprecated here}} 7 void g(void); 8 9 extern int var __attribute__((deprecated)); // expected-note 2 {{'var' has been explicitly marked deprecated here}} 10 a(void)11int a(void) { 12 int (*ptr)(void) = 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; w(void)23int w(void) { 24 return var; // expected-warning {{'var' is deprecated}} 25 } 26 27 int old_fn(void) __attribute__ ((deprecated));// expected-note {{'old_fn' has been explicitly marked deprecated here}} 28 int old_fn(void); 29 int (*fn_ptr)(void) = old_fn; // expected-warning {{'old_fn' is deprecated}} 30 old_fn(void)31int old_fn(void) { 32 return old_fn()+1; // no warning, deprecated functions can use deprecated symbols. 33 } 34 35 36 struct foo { 37 int x __attribute__((deprecated)); // expected-note 3 {{'x' has been explicitly marked deprecated here}} 38 }; 39 test1(struct foo * F)40void test1(struct foo *F) { 41 ++F->x; // expected-warning {{'x' is deprecated}} 42 struct foo f1 = { .x = 17 }; // expected-warning {{'x' is deprecated}} 43 struct foo f2 = { 17 }; // expected-warning {{'x' is deprecated}} 44 } 45 46 typedef struct foo foo_dep __attribute__((deprecated)); // expected-note 12 {{'foo_dep' has been explicitly marked deprecated here}} 47 foo_dep *test2; // expected-warning {{'foo_dep' is deprecated}} 48 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}} 51 52 struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}} 53 54 55 // These should not warn because the actually declaration itself is deprecated. 56 foo_dep *test4 __attribute__((deprecated)); 57 struct bar_dep *test5 __attribute__((deprecated)); 58 59 typedef foo_dep test6(struct bar_dep*); // expected-warning {{'foo_dep' is deprecated}} \ 60 // expected-warning {{'bar_dep' is deprecated}} 61 typedef foo_dep test7(struct bar_dep*) __attribute__((deprecated)); 62 test8(char * p)63int test8(char *p) { 64 p += sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}} 65 66 foo_dep *ptr; // expected-warning {{'foo_dep' is deprecated}} 67 ptr = (foo_dep*) p; // expected-warning {{'foo_dep' is deprecated}} 68 69 int func(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}} 70 return func(ptr); 71 } 72 73 foo_dep *test9(void) __attribute__((deprecated)); test9(void)74foo_dep *test9(void) { 75 void* myalloc(unsigned long); 76 77 foo_dep *ptr 78 = (foo_dep*) 79 myalloc(sizeof(foo_dep)); 80 return ptr; 81 } 82 83 void test10(void) __attribute__((deprecated)); test10(void)84void test10(void) { 85 if (sizeof(foo_dep) == sizeof(void*)) { 86 } 87 foo_dep *localfunc(void); 88 foo_dep localvar; 89 } 90 91 char test11[sizeof(foo_dep)] __attribute__((deprecated)); 92 char test12[sizeof(foo_dep)]; // expected-warning {{'foo_dep' is deprecated}} 93 94 int test13(foo_dep *foo) __attribute__((deprecated)); 95 int test14(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}} 96 97 unsigned long test15 = sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}} 98 unsigned long test16 __attribute__((deprecated)) 99 = sizeof(foo_dep); 100 101 foo_dep test17, // expected-warning {{'foo_dep' is deprecated}} 102 test18 __attribute__((deprecated)), 103 test19; 104 105 enum __attribute__((deprecated)) Test20 { // expected-note 2 {{'Test20' has been explicitly marked deprecated here}} 106 test20_a __attribute__((deprecated)), // expected-note {{'test20_a' has been explicitly marked deprecated here}} 107 test20_b 108 }; test20(void)109void test20(void) { 110 enum Test20 f; // expected-warning {{'Test20' is deprecated}} 111 f = test20_a; // expected-warning {{'test20_a' is deprecated}} 112 f = test20_b; // expected-warning {{'test20_b' is deprecated}} 113 } 114 115 char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1]; 116 117 struct test22 { 118 foo_dep a __attribute((deprecated)); 119 foo_dep b; // expected-warning {{'foo_dep' is deprecated}} 120 foo_dep c, d __attribute((deprecated)); // expected-warning {{'foo_dep' is deprecated}} 121 __attribute((deprecated)) foo_dep e, f; 122 }; 123 124 typedef int test23_ty __attribute((deprecated)); 125 // Redefining a typedef is a C11 feature. 126 #if __STDC_VERSION__ <= 199901L 127 // expected-note@-3 {{'test23_ty' has been explicitly marked deprecated here}} 128 #else 129 // expected-note@-5 {{'test23_ty' has been explicitly marked deprecated here}} 130 typedef int test23_ty; 131 #endif 132 test23_ty test23_v; // expected-warning {{'test23_ty' is deprecated}} 133