Fix the clang-wpa example.
[clang.git] / test / Sema / attr-deprecated.c
blobb26171b86b0adcc26038a1bd192289497e217237
1 // RUN: %clang_cc1 %s -verify -fsyntax-only
3 int f() __attribute__((deprecated));
4 void g() __attribute__((deprecated));
5 void g();
7 extern int var __attribute__((deprecated));
9 int a() {
10 int (*ptr)() = f; // expected-warning {{'f' is deprecated}}
11 f(); // expected-warning {{'f' is deprecated}}
13 // test if attributes propagate to functions
14 g(); // expected-warning {{'g' is deprecated}}
16 return var; // expected-warning {{'var' is deprecated}}
19 // test if attributes propagate to variables
20 extern int var;
21 int w() {
22 return var; // expected-warning {{'var' is deprecated}}
25 int old_fn() __attribute__ ((deprecated));
26 int old_fn();
27 int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}}
29 int old_fn() {
30 return old_fn()+1; // no warning, deprecated functions can use deprecated symbols.
34 struct foo {
35 int x __attribute__((deprecated));
38 void test1(struct foo *F) {
39 ++F->x; // expected-warning {{'x' is deprecated}}
42 typedef struct foo foo_dep __attribute__((deprecated));
43 foo_dep *test2; // expected-warning {{'foo_dep' is deprecated}}
45 struct bar_dep __attribute__((deprecated,
46 invalid_attribute)); // expected-warning {{unknown attribute 'invalid_attribute' ignored}}
48 struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}}
51 // These should not warn because the actually declaration itself is deprecated.
52 // rdar://6756623
53 foo_dep *test4 __attribute__((deprecated));
54 struct bar_dep *test5 __attribute__((deprecated));
56 typedef foo_dep test6(struct bar_dep*); // expected-warning {{'foo_dep' is deprecated}} \
57 // expected-warning {{'bar_dep' is deprecated}}
58 typedef foo_dep test7(struct bar_dep*) __attribute__((deprecated));
60 int test8(char *p) {
61 p += sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}}
63 foo_dep *ptr; // expected-warning {{'foo_dep' is deprecated}}
64 ptr = (foo_dep*) p; // expected-warning {{'foo_dep' is deprecated}}
66 int func(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}}
67 return func(ptr);
70 foo_dep *test9(void) __attribute__((deprecated));
71 foo_dep *test9(void) {
72 void* myalloc(unsigned long);
74 foo_dep *ptr
75 = (foo_dep*)
76 myalloc(sizeof(foo_dep));
77 return ptr;
80 void test10(void) __attribute__((deprecated));
81 void test10(void) {
82 if (sizeof(foo_dep) == sizeof(void*)) {
84 foo_dep *localfunc(void);
85 foo_dep localvar;
88 char test11[sizeof(foo_dep)] __attribute__((deprecated));
89 char test12[sizeof(foo_dep)]; // expected-warning {{'foo_dep' is deprecated}}
91 int test13(foo_dep *foo) __attribute__((deprecated));
92 int test14(foo_dep *foo); // expected-warning {{'foo_dep' is deprecated}}
94 unsigned long test15 = sizeof(foo_dep); // expected-warning {{'foo_dep' is deprecated}}
95 unsigned long test16 __attribute__((deprecated))
96 = sizeof(foo_dep);
98 foo_dep test17, // expected-warning {{'foo_dep' is deprecated}}
99 test18 __attribute__((deprecated)),
100 test19;
102 // rdar://problem/8518751
103 enum __attribute__((deprecated)) Test20 {
104 test20_a __attribute__((deprecated)),
105 test20_b
107 void test20() {
108 enum Test20 f; // expected-warning {{'Test20' is deprecated}}
109 f = test20_a; // expected-warning {{'test20_a' is deprecated}}
110 f = test20_b;
113 char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1];