blob: d09faf34d7a520b3b8cff05c2dd7d6953ee50378 [file] [log] [blame]
Nick Lewycky3c86a5c2013-02-12 08:08:54 +00001// RUN: %clang_cc1 %s -verify -fexceptions
Anders Carlsson0f44b5a2009-08-08 16:55:18 +00002class A {
Fariborz Jahanian350e9562012-05-27 16:59:48 +00003 void f() __attribute__((deprecated)); // expected-note 2 {{declared here}}
Anders Carlsson0f44b5a2009-08-08 16:55:18 +00004 void g(A* a);
Anders Carlssonfb7ef752009-08-08 17:48:49 +00005 void h(A* a) __attribute__((deprecated));
Anders Carlsson0f44b5a2009-08-08 16:55:18 +00006
Fariborz Jahanian350e9562012-05-27 16:59:48 +00007 int b __attribute__((deprecated)); // expected-note 2 {{declared here}}
Anders Carlsson0f44b5a2009-08-08 16:55:18 +00008};
9
10void A::g(A* a)
11{
12 f(); // expected-warning{{'f' is deprecated}}
13 a->f(); // expected-warning{{'f' is deprecated}}
14
15 (void)b; // expected-warning{{'b' is deprecated}}
16 (void)a->b; // expected-warning{{'b' is deprecated}}
17}
Anders Carlssonfb7ef752009-08-08 17:48:49 +000018
19void A::h(A* a)
20{
21 f();
22 a->f();
23
24 (void)b;
25 (void)a->b;
26}
Anders Carlsson0f728562009-09-10 20:48:14 +000027
28struct B {
Fariborz Jahanian350e9562012-05-27 16:59:48 +000029 virtual void f() __attribute__((deprecated)); // expected-note 4 {{declared here}}
Anders Carlssoned90c4e2009-09-11 05:54:14 +000030 void g();
Anders Carlsson0f728562009-09-10 20:48:14 +000031};
32
Anders Carlssoned90c4e2009-09-11 05:54:14 +000033void B::g() {
34 f();
35 B::f(); // expected-warning{{'f' is deprecated}}
36}
37
Anders Carlsson0f728562009-09-10 20:48:14 +000038struct C : B {
39 virtual void f();
Anders Carlssoned90c4e2009-09-11 05:54:14 +000040 void g();
Anders Carlsson0f728562009-09-10 20:48:14 +000041};
42
Anders Carlssoned90c4e2009-09-11 05:54:14 +000043void C::g() {
44 f();
45 C::f();
46 B::f(); // expected-warning{{'f' is deprecated}}
47}
48
Anders Carlsson0f728562009-09-10 20:48:14 +000049void f(B* b, C *c) {
50 b->f();
51 b->B::f(); // expected-warning{{'f' is deprecated}}
52
53 c->f();
54 c->C::f();
55 c->B::f(); // expected-warning{{'f' is deprecated}}
56}
Anders Carlsson8195bc92009-09-13 21:01:57 +000057
58struct D {
59 virtual void f() __attribute__((deprecated));
60};
61
62void D::f() { }
63
64void f(D* d) {
65 d->f();
66}
John McCallb697e082010-05-06 18:15:07 +000067
68
69// Overloaded namespace members.
70namespace test1 {
Fariborz Jahanian350e9562012-05-27 16:59:48 +000071 void foo(int) __attribute__((deprecated)); // expected-note {{declared here}}
John McCallb697e082010-05-06 18:15:07 +000072 void test1() { foo(10); } // expected-warning {{deprecated}}
Fariborz Jahanian350e9562012-05-27 16:59:48 +000073 void foo(short) __attribute__((deprecated)); // expected-note {{declared here}}
John McCallb697e082010-05-06 18:15:07 +000074 void test2(short s) { foo(s); } // expected-warning {{deprecated}}
75 void foo(long);
76 void test3(long l) { foo(l); }
77 struct A {
Fariborz Jahanian350e9562012-05-27 16:59:48 +000078 friend void foo(A*) __attribute__((deprecated)); // expected-note {{declared here}}
John McCallb697e082010-05-06 18:15:07 +000079 };
80 void test4(A *a) { foo(a); } // expected-warning {{deprecated}}
81
82 namespace ns {
83 struct Foo {};
Fariborz Jahanian350e9562012-05-27 16:59:48 +000084 void foo(const Foo &f) __attribute__((deprecated)); // expected-note {{declared here}}
John McCallb697e082010-05-06 18:15:07 +000085 }
86 void test5() {
87 foo(ns::Foo()); // expected-warning {{deprecated}}
88 }
89}
90
91// Overloaded class members.
92namespace test2 {
93 struct A {
Fariborz Jahanian350e9562012-05-27 16:59:48 +000094 void foo(int) __attribute__((deprecated)); // expected-note 2 {{declared here}}
John McCallb697e082010-05-06 18:15:07 +000095 void foo(long);
Fariborz Jahanian350e9562012-05-27 16:59:48 +000096 static void bar(int) __attribute__((deprecated)); // expected-note 3 {{declared here}}
John McCallb697e082010-05-06 18:15:07 +000097 static void bar(long);
98
99 void test2(int i, long l);
100 };
101 void test1(int i, long l) {
102 A a;
103 a.foo(i); // expected-warning {{deprecated}}
104 a.foo(l);
105 a.bar(i); // expected-warning {{deprecated}}
106 a.bar(l);
107 A::bar(i); // expected-warning {{deprecated}}
108 A::bar(l);
109 }
110
111 void A::test2(int i, long l) {
112 foo(i); // expected-warning {{deprecated}}
113 foo(l);
114 bar(i); // expected-warning {{deprecated}}
115 bar(l);
116 }
117}
118
119// Overloaded operators.
120namespace test3 {
121 struct A {
122 void operator*(const A &);
Fariborz Jahanian350e9562012-05-27 16:59:48 +0000123 void operator*(int) __attribute__((deprecated)); // expected-note {{declared here}}
John McCallb697e082010-05-06 18:15:07 +0000124 void operator-(const A &) const;
125 };
126 void operator+(const A &, const A &);
Fariborz Jahanian350e9562012-05-27 16:59:48 +0000127 void operator+(const A &, int) __attribute__((deprecated)); // expected-note {{declared here}}
128 void operator-(const A &, int) __attribute__((deprecated)); // expected-note {{declared here}}
John McCallb697e082010-05-06 18:15:07 +0000129
130 void test() {
131 A a, b;
132 a + b;
133 a + 1; // expected-warning {{deprecated}}
134 a - b;
135 a - 1; // expected-warning {{deprecated}}
136 a * b;
137 a * 1; // expected-warning {{deprecated}}
138 }
139}
140
141// Overloaded operator call.
142namespace test4 {
143 struct A {
144 typedef void (*intfn)(int);
145 typedef void (*unintfn)(unsigned);
Fariborz Jahanian350e9562012-05-27 16:59:48 +0000146 operator intfn() __attribute__((deprecated)); // expected-note {{declared here}}
John McCallb697e082010-05-06 18:15:07 +0000147 operator unintfn();
Fariborz Jahanian350e9562012-05-27 16:59:48 +0000148 void operator ()(A &) __attribute__((deprecated)); // expected-note {{declared here}}
John McCallb697e082010-05-06 18:15:07 +0000149 void operator ()(const A &);
150 };
151
152 void test() {
153 A a;
154 a(1); // expected-warning {{deprecated}}
155 a(1U);
156
157 A &b = a;
158 const A &c = a;
159 a(b); // expected-warning {{deprecated}}
160 a(c);
161 }
162}
163
164namespace test5 {
165 struct A {
Eli Friedmanc3b23082012-08-08 21:52:41 +0000166 operator int() __attribute__((deprecated)); // expected-note 3 {{declared here}}
John McCallb697e082010-05-06 18:15:07 +0000167 operator long();
168 };
169 void test1(A a) {
170 int i = a; // expected-warning {{deprecated}}
171 long l = a;
172 }
173
174 void foo(int);
175 void foo(void*);
176 void bar(long);
177 void bar(void*);
178 void test2(A a) {
179 foo(a); // expected-warning {{deprecated}}
180 bar(a);
181 }
182
183 struct B {
184 int myInt;
185 long myLong;
186
187 B(A &a) :
188 myInt(a), // expected-warning {{deprecated}}
189 myLong(a)
190 {}
191 };
192}
John McCall5b629aa2010-10-22 23:36:17 +0000193
194// rdar://problem/8518751
195namespace test6 {
Fariborz Jahanian350e9562012-05-27 16:59:48 +0000196 enum __attribute__((deprecated)) A { // expected-note {{declared here}}
197 a0 // expected-note {{declared here}}
John McCall5b629aa2010-10-22 23:36:17 +0000198 };
199 void testA() {
200 A x; // expected-warning {{'A' is deprecated}}
Fariborz Jahanian39b4fc82011-11-28 19:45:58 +0000201 x = a0; // expected-warning {{'a0' is deprecated}}
John McCall5b629aa2010-10-22 23:36:17 +0000202 }
203
204 enum B {
Fariborz Jahanian350e9562012-05-27 16:59:48 +0000205 b0 __attribute__((deprecated)), // expected-note {{declared here}}
John McCall5b629aa2010-10-22 23:36:17 +0000206 b1
207 };
208 void testB() {
209 B x;
210 x = b0; // expected-warning {{'b0' is deprecated}}
211 x = b1;
212 }
213
214 template <class T> struct C {
Fariborz Jahanian350e9562012-05-27 16:59:48 +0000215 enum __attribute__((deprecated)) Enum { // expected-note {{declared here}}
216 c0 // expected-note {{declared here}}
John McCall5b629aa2010-10-22 23:36:17 +0000217 };
218 };
219 void testC() {
220 C<int>::Enum x; // expected-warning {{'Enum' is deprecated}}
Fariborz Jahanian39b4fc82011-11-28 19:45:58 +0000221 x = C<int>::c0; // expected-warning {{'c0' is deprecated}}
John McCall5b629aa2010-10-22 23:36:17 +0000222 }
223
224 template <class T> struct D {
225 enum Enum {
226 d0,
Fariborz Jahanian350e9562012-05-27 16:59:48 +0000227 d1 __attribute__((deprecated)), // expected-note {{declared here}}
John McCall5b629aa2010-10-22 23:36:17 +0000228 };
229 };
230 void testD() {
231 D<int>::Enum x;
232 x = D<int>::d0;
233 x = D<int>::d1; // expected-warning {{'d1' is deprecated}}
234 }
235}
Nick Lewycky3c86a5c2013-02-12 08:08:54 +0000236
237namespace test7 {
238 struct X {
Nick Lewycky9efe0572013-02-12 08:59:01 +0000239 void* operator new(typeof(sizeof(void*))) __attribute__((deprecated)); // expected-note{{'operator new' declared here}}
Nick Lewycky3c86a5c2013-02-12 08:08:54 +0000240 void operator delete(void *) __attribute__((deprecated)); // expected-note{{'operator delete' declared here}}
241 };
242
243 void test() {
244 X *x = new X; // expected-warning{{'operator new' is deprecated}} expected-warning{{'operator delete' is deprecated}}
245 }
246}