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