attr-deprecated.c revision a5728872c7702ddd09537c95bc3cbd20e1f2fb09
1// RUN: %clang_cc1 %s -verify -fsyntax-only
2
3int f() __attribute__((deprecated));
4void g() __attribute__((deprecated));
5void g();
6
7void z() __attribute__((bogusattr)); // expected-warning {{'bogusattr' attribute ignored}}
8
9extern int var __attribute__((deprecated));
10
11int 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
22extern int var;
23int w() {
24  return var; // expected-warning {{'var' is deprecated}}
25}
26
27int old_fn() __attribute__ ((deprecated));
28int old_fn();
29int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}}
30
31int old_fn() {
32  return old_fn()+1;  // no warning, deprecated functions can use deprecated symbols.
33}
34
35
36struct foo {
37  int x __attribute__((deprecated));
38};
39
40void test1(struct foo *F) {
41  ++F->x;  // expected-warning {{'x' is deprecated}}
42}
43
44typedef struct foo foo_dep __attribute__((deprecated));
45foo_dep *test2;    // expected-warning {{'foo_dep' is deprecated}}
46
47struct bar_dep __attribute__((deprecated,
48                              invalid_attribute));  // expected-warning {{'invalid_attribute' attribute ignored}}
49
50struct bar_dep *test3;   // expected-warning {{'bar_dep' is deprecated}}
51
52
53// These should not warn because the actually declaration itself is deprecated.
54// rdar://6756623
55foo_dep *test4 __attribute__((deprecated));
56struct bar_dep *test5 __attribute__((deprecated));
57
58typedef foo_dep test6(struct bar_dep*); // expected-warning {{'foo_dep' is deprecated}} \
59                                        // expected-warning {{'bar_dep' is deprecated}}
60typedef foo_dep test7(struct bar_dep*) __attribute__((deprecated));
61
62int 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
72foo_dep *test9(void) __attribute__((deprecated));
73foo_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
82void test10(void) __attribute__((deprecated));
83void test10(void) {
84  if (sizeof(foo_dep) == sizeof(void*)) {
85  }
86  foo_dep *localfunc(void);
87  foo_dep localvar;
88}
89
90char test11[sizeof(foo_dep)] __attribute__((deprecated));
91char test12[sizeof(foo_dep)]; // expected-warning {{'foo_dep' is deprecated}}
92
93int test13(foo_dep *foo) __attribute__((deprecated));
94int test14(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}}
95
96unsigned long test15 = sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}}
97unsigned long test16 __attribute__((deprecated))
98  = sizeof(foo_dep);
99
100foo_dep test17, // expected-warning {{'foo_dep' is deprecated}}
101        test18 __attribute__((deprecated)),
102        test19;
103