2018-06-05 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / deprecated.c
blob757937871495c01a9bf8e5f7bbee57f18c2f4c9b
1 /* Test __attribute__ ((deprecated)) */
2 /* { dg-do compile } */
3 /* { dg-options "-Wdeprecated-declarations" } */
5 #if 1
6 typedef int INT1 __attribute__((deprecated));
7 typedef INT1 INT2 __attribute__ ((__deprecated__));
9 typedef INT1 INT1a; /* { dg-warning "'INT1' is deprecated" } */
10 typedef INT1 INT1b __attribute__ ((deprecated));
12 INT1 should_be_unavailable; /* { dg-warning "'INT1' is deprecated" } */
13 INT1a should_not_be_deprecated;
15 INT1 f1(void) __attribute__ ((deprecated));
16 INT1 f2(void) { return 0; } /* { dg-warning "'INT1' is deprecated" } */
18 INT2 f3(void) __attribute__ ((__deprecated__));
19 INT2 f4(void) { return 0; } /* { dg-warning "'INT2' is deprecated" } */
20 int f5(INT2 x); /* { dg-warning "'INT2' is deprecated" } */
21 int f6(INT2 x) __attribute__ ((__deprecated__)); /* { dg-warning "'INT2' is deprecated" } */
23 typedef enum {red, green, blue} Color __attribute__((deprecated));
25 int g1;
26 int g2 __attribute__ ((deprecated));
27 int g3 __attribute__ ((__deprecated__));
28 Color k; /* { dg-warning "'Color' is deprecated" } */
30 typedef struct {
31 int field1;
32 int field2 __attribute__ ((deprecated));
33 int field3;
34 int field4 __attribute__ ((__deprecated__));
35 union {
36 int field5;
37 int field6 __attribute__ ((deprecated));
38 } u1;
39 int field7:1;
40 int field8:1 __attribute__ ((deprecated));
41 union {
42 int field9;
43 int field10;
44 } u2 __attribute__ ((deprecated));
45 } S1;
47 int func1()
49 INT1 w; /* { dg-warning "'INT1' is deprecated" } */
50 int x __attribute__ ((deprecated));
51 int y __attribute__ ((__deprecated__));
52 int z;
53 int (*pf)() = f1; /* { dg-warning "'f1' is deprecated" } */
55 z = w + x + y + g1 + g2 + g3; /* { dg-warning "'x' is deprecated" } */
56 /* { dg-warning "'y' is deprecated" "y" { target *-*-* } .-1 } */
57 /* { dg-warning "'g2' is deprecated" "g2" { target *-*-* } .-2 } */
58 /* { dg-warning "'g3' is deprecated" "g3" { target *-*-* } .-3 } */
59 return f1(); /* { dg-warning "'f1' is deprecated" "f1" } */
62 int func2(S1 *p)
64 S1 lp;
66 if (p->field1)
67 return p->field2; /* { dg-warning "'field2' is deprecated" } */
68 else if (lp.field4) /* { dg-warning "'field4' is deprecated" } */
69 return p->field3;
71 p->u1.field5 = g1 + p->field7;
72 p->u2.field9; /* { dg-warning "'u2' is deprecated" } */
73 return p->u1.field6 + p->field8; /* { dg-warning "'field6' is deprecated" } */
74 /* { dg-warning "'field8' is deprecated" "field8" { target *-*-* } .-1 } */
77 struct SS1 {
78 int x;
79 INT1 y; /* { dg-warning "'INT1' is deprecated" } */
80 } __attribute__ ((deprecated));
82 struct SS1 *p1; /* { dg-warning "'SS1' is deprecated" } */
84 struct __attribute__ ((__deprecated__)) SS2 {
85 int x;
86 INT1 y; /* { dg-warning "'INT1' is deprecated" } */
89 struct SS2 *p2; /* { dg-warning "'SS2' is deprecated" } */
90 #endif
92 #ifdef __cplusplus
93 class T {
94 public:
95 void member1(int) __attribute__ ((deprecated));
96 void member2(INT1) __attribute__ ((__deprecated__));
97 int member3(T *);
98 int x;
99 } __attribute__ ((deprecated));
101 T *p2;
103 inline void T::member1(int) {}
105 int T::member2(T *p)
107 p->member1(1); /* { xxdg-warning "'member1' is deprecated" } */
108 (*p).member1(2); /* { xxdg-warning "'member1' is deprecated" } */
109 p->member2(1); /* { xxdg-warning "'member2' is deprecated" } */
110 (*p).member2(2); /* { xxdg-warning "'member2' is deprecated" } */
111 p->member3(p);
112 (*p).member3(p);
113 return f1(); /* { xxdg-warning "'f1' is deprecated" } */
115 #endif