attr-deprecated.c revision 4820908be98f340a4c2a563a622ae693a7219c50
1// RUN: %clang_cc1 %s -verify -fsyntax-only
2
3int f() __attribute__((deprecated));
4void g() __attribute__((deprecated));
5void g();
6
7extern int var __attribute__((deprecated));
8
9int a() {
10  int (*ptr)() = f; // expected-warning {{'f' is deprecated}}
11  f(); // expected-warning {{'f' is deprecated}}
12
13  // test if attributes propagate to functions
14  g(); // expected-warning {{'g' is deprecated}}
15
16  return var; // expected-warning {{'var' is deprecated}}
17}
18
19// test if attributes propagate to variables
20extern int var;
21int w() {
22  return var; // expected-warning {{'var' is deprecated}}
23}
24
25int old_fn() __attribute__ ((deprecated));
26int old_fn();
27int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}}
28
29int old_fn() {
30  return old_fn()+1;  // no warning, deprecated functions can use deprecated symbols.
31}
32
33
34struct foo {
35  int x __attribute__((deprecated));
36};
37
38void test1(struct foo *F) {
39  ++F->x;  // expected-warning {{'x' is deprecated}}
40}
41
42typedef struct foo foo_dep __attribute__((deprecated));
43foo_dep *test2;    // expected-warning {{'foo_dep' is deprecated}}
44
45struct bar_dep __attribute__((deprecated,
46                              invalid_attribute));  // expected-warning {{unknown attribute 'invalid_attribute' ignored}}
47
48struct bar_dep *test3;   // expected-warning {{'bar_dep' is deprecated}}
49
50
51// These should not warn because the actually declaration itself is deprecated.
52// rdar://6756623
53foo_dep *test4 __attribute__((deprecated));
54struct bar_dep *test5 __attribute__((deprecated));
55
56typedef foo_dep test6(struct bar_dep*); // expected-warning {{'foo_dep' is deprecated}} \
57                                        // expected-warning {{'bar_dep' is deprecated}}
58typedef foo_dep test7(struct bar_dep*) __attribute__((deprecated));
59
60int test8(char *p) {
61  p += sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}}
62
63  foo_dep *ptr;         // expected-warning {{'foo_dep' is deprecated}}
64  ptr = (foo_dep*) p;   // expected-warning {{'foo_dep' is deprecated}}
65
66  int func(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}}
67  return func(ptr);
68}
69
70foo_dep *test9(void) __attribute__((deprecated));
71foo_dep *test9(void) {
72  void* myalloc(unsigned long);
73
74  foo_dep *ptr
75    = (foo_dep*)
76        myalloc(sizeof(foo_dep));
77  return ptr;
78}
79
80void test10(void) __attribute__((deprecated));
81void test10(void) {
82  if (sizeof(foo_dep) == sizeof(void*)) {
83  }
84  foo_dep *localfunc(void);
85  foo_dep localvar;
86}
87
88char test11[sizeof(foo_dep)] __attribute__((deprecated));
89char test12[sizeof(foo_dep)]; // expected-warning {{'foo_dep' is deprecated}}
90
91int test13(foo_dep *foo) __attribute__((deprecated));
92int test14(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}}
93
94unsigned long test15 = sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}}
95unsigned long test16 __attribute__((deprecated))
96  = sizeof(foo_dep);
97
98foo_dep test17, // expected-warning {{'foo_dep' is deprecated}}
99        test18 __attribute__((deprecated)),
100        test19;
101
102// rdar://problem/8518751
103enum __attribute__((deprecated)) Test20 {
104  test20_a __attribute__((deprecated)),
105  test20_b
106};
107void test20() {
108  enum Test20 f; // expected-warning {{'Test20' is deprecated}}
109  f = test20_a; // expected-warning {{'test20_a' is deprecated}}
110  f = test20_b;
111}
112
113char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1];
114