xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/attr-deprecated.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -verify -fexceptions
2*f4a2713aSLionel Sambuc class A {
3*f4a2713aSLionel Sambuc   void f() __attribute__((deprecated)); // expected-note 2 {{declared here}}
4*f4a2713aSLionel Sambuc   void g(A* a);
5*f4a2713aSLionel Sambuc   void h(A* a) __attribute__((deprecated));
6*f4a2713aSLionel Sambuc 
7*f4a2713aSLionel Sambuc   int b __attribute__((deprecated)); // expected-note 2 {{declared here}}
8*f4a2713aSLionel Sambuc };
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc void A::g(A* a)
11*f4a2713aSLionel Sambuc {
12*f4a2713aSLionel Sambuc   f(); // expected-warning{{'f' is deprecated}}
13*f4a2713aSLionel Sambuc   a->f(); // expected-warning{{'f' is deprecated}}
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc   (void)b; // expected-warning{{'b' is deprecated}}
16*f4a2713aSLionel Sambuc   (void)a->b; // expected-warning{{'b' is deprecated}}
17*f4a2713aSLionel Sambuc }
18*f4a2713aSLionel Sambuc 
19*f4a2713aSLionel Sambuc void A::h(A* a)
20*f4a2713aSLionel Sambuc {
21*f4a2713aSLionel Sambuc   f();
22*f4a2713aSLionel Sambuc   a->f();
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc   (void)b;
25*f4a2713aSLionel Sambuc   (void)a->b;
26*f4a2713aSLionel Sambuc }
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc struct B {
29*f4a2713aSLionel Sambuc   virtual void f() __attribute__((deprecated)); // expected-note 4 {{declared here}}
30*f4a2713aSLionel Sambuc   void g();
31*f4a2713aSLionel Sambuc };
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc void B::g() {
34*f4a2713aSLionel Sambuc   f();
35*f4a2713aSLionel Sambuc   B::f(); // expected-warning{{'f' is deprecated}}
36*f4a2713aSLionel Sambuc }
37*f4a2713aSLionel Sambuc 
38*f4a2713aSLionel Sambuc struct C : B {
39*f4a2713aSLionel Sambuc   virtual void f();
40*f4a2713aSLionel Sambuc   void g();
41*f4a2713aSLionel Sambuc };
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc void C::g() {
44*f4a2713aSLionel Sambuc   f();
45*f4a2713aSLionel Sambuc   C::f();
46*f4a2713aSLionel Sambuc   B::f(); // expected-warning{{'f' is deprecated}}
47*f4a2713aSLionel Sambuc }
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc void f(B* b, C *c) {
50*f4a2713aSLionel Sambuc   b->f();
51*f4a2713aSLionel Sambuc   b->B::f(); // expected-warning{{'f' is deprecated}}
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc   c->f();
54*f4a2713aSLionel Sambuc   c->C::f();
55*f4a2713aSLionel Sambuc   c->B::f(); // expected-warning{{'f' is deprecated}}
56*f4a2713aSLionel Sambuc }
57*f4a2713aSLionel Sambuc 
58*f4a2713aSLionel Sambuc struct D {
59*f4a2713aSLionel Sambuc   virtual void f() __attribute__((deprecated));
60*f4a2713aSLionel Sambuc };
61*f4a2713aSLionel Sambuc 
62*f4a2713aSLionel Sambuc void D::f() { }
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc void f(D* d) {
65*f4a2713aSLionel Sambuc   d->f();
66*f4a2713aSLionel Sambuc }
67*f4a2713aSLionel Sambuc 
68*f4a2713aSLionel Sambuc 
69*f4a2713aSLionel Sambuc // Overloaded namespace members.
70*f4a2713aSLionel Sambuc namespace test1 {
71*f4a2713aSLionel Sambuc   void foo(int) __attribute__((deprecated)); // expected-note {{declared here}}
72*f4a2713aSLionel Sambuc   void test1() { foo(10); } // expected-warning {{deprecated}}
73*f4a2713aSLionel Sambuc   void foo(short) __attribute__((deprecated)); // expected-note {{declared here}}
74*f4a2713aSLionel Sambuc   void test2(short s) { foo(s); } // expected-warning {{deprecated}}
75*f4a2713aSLionel Sambuc   void foo(long);
76*f4a2713aSLionel Sambuc   void test3(long l) { foo(l); }
77*f4a2713aSLionel Sambuc   struct A {
78*f4a2713aSLionel Sambuc     friend void foo(A*) __attribute__((deprecated)); // expected-note {{declared here}}
79*f4a2713aSLionel Sambuc   };
80*f4a2713aSLionel Sambuc   void test4(A *a) { foo(a); } // expected-warning {{deprecated}}
81*f4a2713aSLionel Sambuc 
82*f4a2713aSLionel Sambuc   namespace ns {
83*f4a2713aSLionel Sambuc     struct Foo {};
84*f4a2713aSLionel Sambuc     void foo(const Foo &f) __attribute__((deprecated)); // expected-note {{declared here}}
85*f4a2713aSLionel Sambuc   }
86*f4a2713aSLionel Sambuc   void test5() {
87*f4a2713aSLionel Sambuc     foo(ns::Foo()); // expected-warning {{deprecated}}
88*f4a2713aSLionel Sambuc   }
89*f4a2713aSLionel Sambuc }
90*f4a2713aSLionel Sambuc 
91*f4a2713aSLionel Sambuc // Overloaded class members.
92*f4a2713aSLionel Sambuc namespace test2 {
93*f4a2713aSLionel Sambuc   struct A {
94*f4a2713aSLionel Sambuc     void foo(int) __attribute__((deprecated)); // expected-note 2 {{declared here}}
95*f4a2713aSLionel Sambuc     void foo(long);
96*f4a2713aSLionel Sambuc     static void bar(int) __attribute__((deprecated)); // expected-note 3 {{declared here}}
97*f4a2713aSLionel Sambuc     static void bar(long);
98*f4a2713aSLionel Sambuc 
99*f4a2713aSLionel Sambuc     void test2(int i, long l);
100*f4a2713aSLionel Sambuc   };
101*f4a2713aSLionel Sambuc   void test1(int i, long l) {
102*f4a2713aSLionel Sambuc     A a;
103*f4a2713aSLionel Sambuc     a.foo(i); // expected-warning {{deprecated}}
104*f4a2713aSLionel Sambuc     a.foo(l);
105*f4a2713aSLionel Sambuc     a.bar(i); // expected-warning {{deprecated}}
106*f4a2713aSLionel Sambuc     a.bar(l);
107*f4a2713aSLionel Sambuc     A::bar(i); // expected-warning {{deprecated}}
108*f4a2713aSLionel Sambuc     A::bar(l);
109*f4a2713aSLionel Sambuc   }
110*f4a2713aSLionel Sambuc 
111*f4a2713aSLionel Sambuc   void A::test2(int i, long l) {
112*f4a2713aSLionel Sambuc     foo(i); // expected-warning {{deprecated}}
113*f4a2713aSLionel Sambuc     foo(l);
114*f4a2713aSLionel Sambuc     bar(i); // expected-warning {{deprecated}}
115*f4a2713aSLionel Sambuc     bar(l);
116*f4a2713aSLionel Sambuc   }
117*f4a2713aSLionel Sambuc }
118*f4a2713aSLionel Sambuc 
119*f4a2713aSLionel Sambuc // Overloaded operators.
120*f4a2713aSLionel Sambuc namespace test3 {
121*f4a2713aSLionel Sambuc   struct A {
122*f4a2713aSLionel Sambuc     void operator*(const A &);
123*f4a2713aSLionel Sambuc     void operator*(int) __attribute__((deprecated)); // expected-note {{declared here}}
124*f4a2713aSLionel Sambuc     void operator-(const A &) const;
125*f4a2713aSLionel Sambuc   };
126*f4a2713aSLionel Sambuc   void operator+(const A &, const A &);
127*f4a2713aSLionel Sambuc   void operator+(const A &, int) __attribute__((deprecated)); // expected-note {{declared here}}
128*f4a2713aSLionel Sambuc   void operator-(const A &, int) __attribute__((deprecated)); // expected-note {{declared here}}
129*f4a2713aSLionel Sambuc 
130*f4a2713aSLionel Sambuc   void test() {
131*f4a2713aSLionel Sambuc     A a, b;
132*f4a2713aSLionel Sambuc     a + b;
133*f4a2713aSLionel Sambuc     a + 1; // expected-warning {{deprecated}}
134*f4a2713aSLionel Sambuc     a - b;
135*f4a2713aSLionel Sambuc     a - 1; // expected-warning {{deprecated}}
136*f4a2713aSLionel Sambuc     a * b;
137*f4a2713aSLionel Sambuc     a * 1; // expected-warning {{deprecated}}
138*f4a2713aSLionel Sambuc   }
139*f4a2713aSLionel Sambuc }
140*f4a2713aSLionel Sambuc 
141*f4a2713aSLionel Sambuc // Overloaded operator call.
142*f4a2713aSLionel Sambuc namespace test4 {
143*f4a2713aSLionel Sambuc   struct A {
144*f4a2713aSLionel Sambuc     typedef void (*intfn)(int);
145*f4a2713aSLionel Sambuc     typedef void (*unintfn)(unsigned);
146*f4a2713aSLionel Sambuc     operator intfn() __attribute__((deprecated)); // expected-note {{declared here}}
147*f4a2713aSLionel Sambuc     operator unintfn();
148*f4a2713aSLionel Sambuc     void operator ()(A &) __attribute__((deprecated)); // expected-note {{declared here}}
149*f4a2713aSLionel Sambuc     void operator ()(const A &);
150*f4a2713aSLionel Sambuc   };
151*f4a2713aSLionel Sambuc 
152*f4a2713aSLionel Sambuc   void test() {
153*f4a2713aSLionel Sambuc     A a;
154*f4a2713aSLionel Sambuc     a(1); // expected-warning {{deprecated}}
155*f4a2713aSLionel Sambuc     a(1U);
156*f4a2713aSLionel Sambuc 
157*f4a2713aSLionel Sambuc     A &b = a;
158*f4a2713aSLionel Sambuc     const A &c = a;
159*f4a2713aSLionel Sambuc     a(b); // expected-warning {{deprecated}}
160*f4a2713aSLionel Sambuc     a(c);
161*f4a2713aSLionel Sambuc   }
162*f4a2713aSLionel Sambuc }
163*f4a2713aSLionel Sambuc 
164*f4a2713aSLionel Sambuc namespace test5 {
165*f4a2713aSLionel Sambuc   struct A {
166*f4a2713aSLionel Sambuc     operator int() __attribute__((deprecated)); // expected-note 3 {{declared here}}
167*f4a2713aSLionel Sambuc     operator long();
168*f4a2713aSLionel Sambuc   };
169*f4a2713aSLionel Sambuc   void test1(A a) {
170*f4a2713aSLionel Sambuc     int i = a; // expected-warning {{deprecated}}
171*f4a2713aSLionel Sambuc     long l = a;
172*f4a2713aSLionel Sambuc   }
173*f4a2713aSLionel Sambuc 
174*f4a2713aSLionel Sambuc   void foo(int);
175*f4a2713aSLionel Sambuc   void foo(void*);
176*f4a2713aSLionel Sambuc   void bar(long);
177*f4a2713aSLionel Sambuc   void bar(void*);
178*f4a2713aSLionel Sambuc   void test2(A a) {
179*f4a2713aSLionel Sambuc     foo(a); // expected-warning {{deprecated}}
180*f4a2713aSLionel Sambuc     bar(a);
181*f4a2713aSLionel Sambuc   }
182*f4a2713aSLionel Sambuc 
183*f4a2713aSLionel Sambuc   struct B {
184*f4a2713aSLionel Sambuc     int myInt;
185*f4a2713aSLionel Sambuc     long myLong;
186*f4a2713aSLionel Sambuc 
187*f4a2713aSLionel Sambuc     B(A &a) :
188*f4a2713aSLionel Sambuc       myInt(a), // expected-warning {{deprecated}}
189*f4a2713aSLionel Sambuc       myLong(a)
190*f4a2713aSLionel Sambuc     {}
191*f4a2713aSLionel Sambuc   };
192*f4a2713aSLionel Sambuc }
193*f4a2713aSLionel Sambuc 
194*f4a2713aSLionel Sambuc // rdar://problem/8518751
195*f4a2713aSLionel Sambuc namespace test6 {
196*f4a2713aSLionel Sambuc   enum __attribute__((deprecated)) A { // expected-note {{declared here}}
197*f4a2713aSLionel Sambuc     a0 // expected-note {{declared here}}
198*f4a2713aSLionel Sambuc   };
199*f4a2713aSLionel Sambuc   void testA() {
200*f4a2713aSLionel Sambuc     A x; // expected-warning {{'A' is deprecated}}
201*f4a2713aSLionel Sambuc     x = a0; // expected-warning {{'a0' is deprecated}}
202*f4a2713aSLionel Sambuc   }
203*f4a2713aSLionel Sambuc 
204*f4a2713aSLionel Sambuc   enum B {
205*f4a2713aSLionel Sambuc     b0 __attribute__((deprecated)), // expected-note {{declared here}}
206*f4a2713aSLionel Sambuc     b1
207*f4a2713aSLionel Sambuc   };
208*f4a2713aSLionel Sambuc   void testB() {
209*f4a2713aSLionel Sambuc     B x;
210*f4a2713aSLionel Sambuc     x = b0; // expected-warning {{'b0' is deprecated}}
211*f4a2713aSLionel Sambuc     x = b1;
212*f4a2713aSLionel Sambuc   }
213*f4a2713aSLionel Sambuc 
214*f4a2713aSLionel Sambuc   template <class T> struct C {
215*f4a2713aSLionel Sambuc     enum __attribute__((deprecated)) Enum { // expected-note {{declared here}}
216*f4a2713aSLionel Sambuc       c0 // expected-note {{declared here}}
217*f4a2713aSLionel Sambuc     };
218*f4a2713aSLionel Sambuc   };
219*f4a2713aSLionel Sambuc   void testC() {
220*f4a2713aSLionel Sambuc     C<int>::Enum x; // expected-warning {{'Enum' is deprecated}}
221*f4a2713aSLionel Sambuc     x = C<int>::c0; // expected-warning {{'c0' is deprecated}}
222*f4a2713aSLionel Sambuc   }
223*f4a2713aSLionel Sambuc 
224*f4a2713aSLionel Sambuc   template <class T> struct D {
225*f4a2713aSLionel Sambuc     enum Enum {
226*f4a2713aSLionel Sambuc       d0,
227*f4a2713aSLionel Sambuc       d1 __attribute__((deprecated)), // expected-note {{declared here}}
228*f4a2713aSLionel Sambuc     };
229*f4a2713aSLionel Sambuc   };
230*f4a2713aSLionel Sambuc   void testD() {
231*f4a2713aSLionel Sambuc     D<int>::Enum x;
232*f4a2713aSLionel Sambuc     x = D<int>::d0;
233*f4a2713aSLionel Sambuc     x = D<int>::d1; // expected-warning {{'d1' is deprecated}}
234*f4a2713aSLionel Sambuc   }
235*f4a2713aSLionel Sambuc }
236*f4a2713aSLionel Sambuc 
237*f4a2713aSLionel Sambuc namespace test7 {
238*f4a2713aSLionel Sambuc   struct X {
239*f4a2713aSLionel Sambuc     void* operator new(typeof(sizeof(void*))) __attribute__((deprecated));  // expected-note{{'operator new' declared here}}
240*f4a2713aSLionel Sambuc     void operator delete(void *) __attribute__((deprecated));  // expected-note{{'operator delete' declared here}}
241*f4a2713aSLionel Sambuc   };
242*f4a2713aSLionel Sambuc 
243*f4a2713aSLionel Sambuc   void test() {
244*f4a2713aSLionel Sambuc     X *x = new X;  // expected-warning{{'operator new' is deprecated}} expected-warning{{'operator delete' is deprecated}}
245*f4a2713aSLionel Sambuc   }
246*f4a2713aSLionel Sambuc }
247*f4a2713aSLionel Sambuc 
248*f4a2713aSLionel Sambuc // rdar://problem/15044218
249*f4a2713aSLionel Sambuc typedef struct TDS {
250*f4a2713aSLionel Sambuc } TDS __attribute__((deprecated)); // expected-note {{'TDS' declared here}}
251*f4a2713aSLionel Sambuc TDS tds; // expected-warning {{'TDS' is deprecated}}
252*f4a2713aSLionel Sambuc struct TDS tds2; // no warning, attribute only applies to the typedef.
253