blob: eab5a1c0ec082d401f989850e69ac03d5fd4fc7a [file] [log] [blame]
Nick Lewyckya096b142013-02-12 08:08:54 +00001// RUN: %clang_cc1 %s -verify -fexceptions
Anders Carlsson21776b72009-08-08 16:55:18 +00002class A {
Ted Kremenekb79ee572013-12-18 23:30:06 +00003 void f() __attribute__((deprecated)); // expected-note 2 {{'f' has been explicitly marked deprecated here}}
Anders Carlsson21776b72009-08-08 16:55:18 +00004 void g(A* a);
Anders Carlsson5fd7dad2009-08-08 17:48:49 +00005 void h(A* a) __attribute__((deprecated));
Anders Carlsson21776b72009-08-08 16:55:18 +00006
Ted Kremenekb79ee572013-12-18 23:30:06 +00007 int b __attribute__((deprecated)); // expected-note 2 {{'b' has been explicitly marked deprecated here}}
Anders Carlsson21776b72009-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 Carlsson5fd7dad2009-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 Carlsson04e1e222009-09-10 20:48:14 +000027
28struct B {
Davide Italianof179e362015-07-22 00:30:58 +000029 virtual void f() __attribute__((deprecated)); // expected-note 6 {{'f' has been explicitly marked deprecated here}}
Anders Carlsson99056f22009-09-11 05:54:14 +000030 void g();
Anders Carlsson04e1e222009-09-10 20:48:14 +000031};
32
Anders Carlsson99056f22009-09-11 05:54:14 +000033void B::g() {
Davide Italianof179e362015-07-22 00:30:58 +000034 f(); // expected-warning{{'f' is deprecated}}
Anders Carlsson99056f22009-09-11 05:54:14 +000035 B::f(); // expected-warning{{'f' is deprecated}}
36}
37
Anders Carlsson04e1e222009-09-10 20:48:14 +000038struct C : B {
39 virtual void f();
Anders Carlsson99056f22009-09-11 05:54:14 +000040 void g();
Anders Carlsson04e1e222009-09-10 20:48:14 +000041};
42
Anders Carlsson99056f22009-09-11 05:54:14 +000043void C::g() {
44 f();
45 C::f();
46 B::f(); // expected-warning{{'f' is deprecated}}
47}
48
Anders Carlsson04e1e222009-09-10 20:48:14 +000049void f(B* b, C *c) {
Davide Italianof179e362015-07-22 00:30:58 +000050 b->f(); // expected-warning{{'f' is deprecated}}
Anders Carlsson04e1e222009-09-10 20:48:14 +000051 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 Carlsson002f2b32009-09-13 21:01:57 +000057
58struct D {
59 virtual void f() __attribute__((deprecated));
Davide Italiano2b0d13b2015-07-23 02:54:59 +000060 virtual void f(int) __attribute__((deprecated));
61 virtual void f(int, int) __attribute__((deprecated));
Anders Carlsson002f2b32009-09-13 21:01:57 +000062};
63
Davide Italianof179e362015-07-22 00:30:58 +000064void D::f() { } // expected-note{{'f' has been explicitly marked deprecated here}}
Davide Italiano2b0d13b2015-07-23 02:54:59 +000065void D::f(int v) { } // expected-note{{'f' has been explicitly marked deprecated here}}
66void D::f(int v1, int v2) { } // expected-note{{'f' has been explicitly marked deprecated here}}
Anders Carlsson002f2b32009-09-13 21:01:57 +000067
68void f(D* d) {
Davide Italianof179e362015-07-22 00:30:58 +000069 d->f(); // expected-warning{{'f' is deprecated}}
Davide Italiano2b0d13b2015-07-23 02:54:59 +000070 d->f(42); // expected-warning{{'f' is deprecated}}
71 d->f(42, 24); // expected-warning{{'f' is deprecated}}
Anders Carlsson002f2b32009-09-13 21:01:57 +000072}
John McCall4fa0d5f2010-05-06 18:15:07 +000073
74
75// Overloaded namespace members.
76namespace test1 {
Ted Kremenekb79ee572013-12-18 23:30:06 +000077 void foo(int) __attribute__((deprecated)); // expected-note {{'foo' has been explicitly marked deprecated here}}
John McCall4fa0d5f2010-05-06 18:15:07 +000078 void test1() { foo(10); } // expected-warning {{deprecated}}
Ted Kremenekb79ee572013-12-18 23:30:06 +000079 void foo(short) __attribute__((deprecated)); // expected-note {{'foo' has been explicitly marked deprecated here}}
John McCall4fa0d5f2010-05-06 18:15:07 +000080 void test2(short s) { foo(s); } // expected-warning {{deprecated}}
81 void foo(long);
82 void test3(long l) { foo(l); }
83 struct A {
Ted Kremenekb79ee572013-12-18 23:30:06 +000084 friend void foo(A*) __attribute__((deprecated)); // expected-note {{'foo' has been explicitly marked deprecated here}}
John McCall4fa0d5f2010-05-06 18:15:07 +000085 };
86 void test4(A *a) { foo(a); } // expected-warning {{deprecated}}
87
88 namespace ns {
89 struct Foo {};
Ted Kremenekb79ee572013-12-18 23:30:06 +000090 void foo(const Foo &f) __attribute__((deprecated)); // expected-note {{'foo' has been explicitly marked deprecated here}}
John McCall4fa0d5f2010-05-06 18:15:07 +000091 }
92 void test5() {
93 foo(ns::Foo()); // expected-warning {{deprecated}}
94 }
95}
96
97// Overloaded class members.
98namespace test2 {
99 struct A {
Ted Kremenekb79ee572013-12-18 23:30:06 +0000100 void foo(int) __attribute__((deprecated)); // expected-note 2 {{'foo' has been explicitly marked deprecated here}}
John McCall4fa0d5f2010-05-06 18:15:07 +0000101 void foo(long);
Ted Kremenekb79ee572013-12-18 23:30:06 +0000102 static void bar(int) __attribute__((deprecated)); // expected-note 3 {{'bar' has been explicitly marked deprecated here}}
John McCall4fa0d5f2010-05-06 18:15:07 +0000103 static void bar(long);
104
105 void test2(int i, long l);
106 };
107 void test1(int i, long l) {
108 A a;
109 a.foo(i); // expected-warning {{deprecated}}
110 a.foo(l);
111 a.bar(i); // expected-warning {{deprecated}}
112 a.bar(l);
113 A::bar(i); // expected-warning {{deprecated}}
114 A::bar(l);
115 }
116
117 void A::test2(int i, long l) {
118 foo(i); // expected-warning {{deprecated}}
119 foo(l);
120 bar(i); // expected-warning {{deprecated}}
121 bar(l);
122 }
123}
124
125// Overloaded operators.
126namespace test3 {
127 struct A {
128 void operator*(const A &);
Ted Kremenekb79ee572013-12-18 23:30:06 +0000129 void operator*(int) __attribute__((deprecated)); // expected-note {{'operator*' has been explicitly marked deprecated here}}
John McCall4fa0d5f2010-05-06 18:15:07 +0000130 void operator-(const A &) const;
131 };
132 void operator+(const A &, const A &);
Ted Kremenekb79ee572013-12-18 23:30:06 +0000133 void operator+(const A &, int) __attribute__((deprecated)); // expected-note {{'operator+' has been explicitly marked deprecated here}}
134 void operator-(const A &, int) __attribute__((deprecated)); // expected-note {{'operator-' has been explicitly marked deprecated here}}
John McCall4fa0d5f2010-05-06 18:15:07 +0000135
136 void test() {
137 A a, b;
138 a + b;
139 a + 1; // expected-warning {{deprecated}}
140 a - b;
141 a - 1; // expected-warning {{deprecated}}
142 a * b;
143 a * 1; // expected-warning {{deprecated}}
144 }
145}
146
147// Overloaded operator call.
148namespace test4 {
149 struct A {
150 typedef void (*intfn)(int);
151 typedef void (*unintfn)(unsigned);
Ted Kremenekb79ee572013-12-18 23:30:06 +0000152 operator intfn() __attribute__((deprecated)); // expected-note {{'operator void (*)(int)' has been explicitly marked deprecated here}}
John McCall4fa0d5f2010-05-06 18:15:07 +0000153 operator unintfn();
Ted Kremenekb79ee572013-12-18 23:30:06 +0000154 void operator ()(A &) __attribute__((deprecated)); // expected-note {{'operator()' has been explicitly marked deprecated here}}
John McCall4fa0d5f2010-05-06 18:15:07 +0000155 void operator ()(const A &);
156 };
157
158 void test() {
159 A a;
160 a(1); // expected-warning {{deprecated}}
161 a(1U);
162
163 A &b = a;
164 const A &c = a;
165 a(b); // expected-warning {{deprecated}}
166 a(c);
167 }
168}
169
170namespace test5 {
171 struct A {
Ted Kremenekb79ee572013-12-18 23:30:06 +0000172 operator int() __attribute__((deprecated)); // expected-note 3 {{'operator int' has been explicitly marked deprecated here}}
John McCall4fa0d5f2010-05-06 18:15:07 +0000173 operator long();
174 };
175 void test1(A a) {
176 int i = a; // expected-warning {{deprecated}}
177 long l = a;
178 }
179
180 void foo(int);
181 void foo(void*);
182 void bar(long);
183 void bar(void*);
184 void test2(A a) {
185 foo(a); // expected-warning {{deprecated}}
186 bar(a);
187 }
188
189 struct B {
190 int myInt;
191 long myLong;
192
193 B(A &a) :
194 myInt(a), // expected-warning {{deprecated}}
195 myLong(a)
196 {}
197 };
198}
John McCall811a0f52010-10-22 23:36:17 +0000199
200// rdar://problem/8518751
201namespace test6 {
Ted Kremenekb79ee572013-12-18 23:30:06 +0000202 enum __attribute__((deprecated)) A { // expected-note {{'A' has been explicitly marked deprecated here}}
203 a0 // expected-note {{'a0' has been explicitly marked deprecated here}}
John McCall811a0f52010-10-22 23:36:17 +0000204 };
205 void testA() {
206 A x; // expected-warning {{'A' is deprecated}}
Fariborz Jahanian25d09c22011-11-28 19:45:58 +0000207 x = a0; // expected-warning {{'a0' is deprecated}}
John McCall811a0f52010-10-22 23:36:17 +0000208 }
209
210 enum B {
Ted Kremenekb79ee572013-12-18 23:30:06 +0000211 b0 __attribute__((deprecated)), // expected-note {{'b0' has been explicitly marked deprecated here}}
John McCall811a0f52010-10-22 23:36:17 +0000212 b1
213 };
214 void testB() {
215 B x;
216 x = b0; // expected-warning {{'b0' is deprecated}}
217 x = b1;
218 }
219
220 template <class T> struct C {
Ted Kremenekb79ee572013-12-18 23:30:06 +0000221 enum __attribute__((deprecated)) Enum { // expected-note {{'Enum' has been explicitly marked deprecated here}}
222 c0 // expected-note {{'c0' has been explicitly marked deprecated here}}
John McCall811a0f52010-10-22 23:36:17 +0000223 };
224 };
225 void testC() {
226 C<int>::Enum x; // expected-warning {{'Enum' is deprecated}}
Fariborz Jahanian25d09c22011-11-28 19:45:58 +0000227 x = C<int>::c0; // expected-warning {{'c0' is deprecated}}
John McCall811a0f52010-10-22 23:36:17 +0000228 }
229
230 template <class T> struct D {
231 enum Enum {
232 d0,
Ted Kremenekb79ee572013-12-18 23:30:06 +0000233 d1 __attribute__((deprecated)), // expected-note {{'d1' has been explicitly marked deprecated here}}
John McCall811a0f52010-10-22 23:36:17 +0000234 };
235 };
236 void testD() {
237 D<int>::Enum x;
238 x = D<int>::d0;
239 x = D<int>::d1; // expected-warning {{'d1' is deprecated}}
240 }
241}
Nick Lewyckya096b142013-02-12 08:08:54 +0000242
243namespace test7 {
244 struct X {
Ted Kremenekb79ee572013-12-18 23:30:06 +0000245 void* operator new(typeof(sizeof(void*))) __attribute__((deprecated)); // expected-note{{'operator new' has been explicitly marked deprecated here}}
246 void operator delete(void *) __attribute__((deprecated)); // expected-note{{'operator delete' has been explicitly marked deprecated here}}
Nick Lewyckya096b142013-02-12 08:08:54 +0000247 };
248
249 void test() {
250 X *x = new X; // expected-warning{{'operator new' is deprecated}} expected-warning{{'operator delete' is deprecated}}
251 }
252}
Justin Bogner84ff5ee2013-10-08 00:19:09 +0000253
254// rdar://problem/15044218
255typedef struct TDS {
Ted Kremenekb79ee572013-12-18 23:30:06 +0000256} TDS __attribute__((deprecated)); // expected-note {{'TDS' has been explicitly marked deprecated here}}
Justin Bogner84ff5ee2013-10-08 00:19:09 +0000257TDS tds; // expected-warning {{'TDS' is deprecated}}
258struct TDS tds2; // no warning, attribute only applies to the typedef.