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