1 /* warn_unused_result attribute tests. */
2 /* { dg-do compile } */
3 /* { dg-options "-O" } */
5 #define WUR __attribute__((warn_unused_result))
6 #define WURAI __attribute__((warn_unused_result, always_inline)) inline
7 typedef WUR
int (*fnt
) (void);
9 typedef struct { long i
; } A
;
10 typedef struct { long i
; long j
; } B
;
11 typedef struct { char big
[1024]; fnt fn
; } C
;
13 WUR
int check1 (void);
14 WUR
void check2 (void); /* { dg-warning "attribute ignored" } */
15 int foo WUR
; /* { dg-warning "only applies" } */
17 extern WURAI
int check3 (void) { return bar (); }
24 extern WURAI A
check7 (void) { return bar7 (); }
25 extern WURAI B
check8 (void) { return bar8 (); }
26 extern WURAI C
check9 (void) { return bar9 (); }
27 /* This is useful for checking whether return value of statement
28 expressions (returning int in this case) is used. */
29 extern WURAI
int check_int_result (int res
) { return res
; }
30 #define GU(v) ({ int e = 0; (v) = bar (); if ((v) < 23) e = 14; e; })
32 WUR
int check10 (void);
34 extern WURAI
int check11 (void) { return baz (); }
41 const fnt pcheck1
= check1
;
42 const fnt pcheck3
= check3
;
49 i
+= ({ check1 (); });
50 check1 (); /* { dg-warning "ignoring return value of" } */
51 (void) check1 (); /* { dg-warning "ignoring return value of" } */
52 check1 (), bar (); /* { dg-warning "ignoring return value of" } */
59 i
+= ({ check3 (); });
60 check3 (); /* { dg-warning "ignoring return value of" } */
61 (void) check3 (); /* { dg-warning "ignoring return value of" } */
62 check3 (), bar (); /* { dg-warning "ignoring return value of" } */
68 if (({ check4 (); }).i
)
70 check4 (); /* { dg-warning "ignoring return value of" } */
71 (void) check4 (); /* { dg-warning "ignoring return value of" } */
72 check4 (), bar (); /* { dg-warning "ignoring return value of" } */
78 if (({ check5 (); }).j
)
80 check5 (); /* { dg-warning "ignoring return value of" } */
81 (void) check5 (); /* { dg-warning "ignoring return value of" } */
82 check5 (), bar (); /* { dg-warning "ignoring return value of" } */
84 if (c
.big
[12] + c
.big
[29])
86 if (check6 ().big
[27])
88 if (({ check6 (); }).big
[0])
90 check6 (); /* { dg-warning "ignoring return value of" } */
91 (void) check6 (); /* { dg-warning "ignoring return value of" } */
92 check6 (), bar (); /* { dg-warning "ignoring return value of" } */
98 if (({ check7 (); }).i
)
100 check7 (); /* { dg-warning "ignoring return value of" } */
101 (void) check7 (); /* { dg-warning "ignoring return value of" } */
102 check7 (), bar (); /* { dg-warning "ignoring return value of" } */
108 if (({ check8 (); }).j
)
110 check8 (); /* { dg-warning "ignoring return value of" } */
111 (void) check8 (); /* { dg-warning "ignoring return value of" } */
112 check8 (), bar (); /* { dg-warning "ignoring return value of" } */
114 if (c
.big
[12] + c
.big
[29])
116 if (check9 ().big
[27])
118 if (({ check9 (); }).big
[0])
120 check9 (); /* { dg-warning "ignoring return value of" } */
121 (void) check9 (); /* { dg-warning "ignoring return value of" } */
122 check9 (), bar (); /* { dg-warning "ignoring return value of" } */
123 if (check_int_result (GU (j
)))
125 i
+= check_int_result (GU (j
));
126 i
+= ({ check_int_result (GU (j
)); });
127 check_int_result (GU (j
)); /* { dg-warning "ignoring return value of" } */
128 (void) check_int_result (GU (j
)); /* { dg-warning "ignoring return value of" } */
129 check_int_result (GU (j
)), bar (); /* { dg-warning "ignoring return value of" } */
133 i
+= ({ fnptr (); });
134 fnptr (); /* { dg-warning "ignoring return value of" } */
135 (void) fnptr (); /* { dg-warning "ignoring return value of" } */
136 fnptr (), bar (); /* { dg-warning "ignoring return value of" } */
141 i
+= ({ fnptr (); });
142 fnptr (); /* { dg-warning "ignoring return value of" } */
143 (void) fnptr (); /* { dg-warning "ignoring return value of" } */
144 fnptr (), bar (); /* { dg-warning "ignoring return value of" } */
149 i
+= ({ fnptr (); });
150 fnptr (); /* { dg-warning "ignoring return value of" } */
151 (void) fnptr (); /* { dg-warning "ignoring return value of" } */
152 fnptr (), bar (); /* { dg-warning "ignoring return value of" } */
156 i
+= ({ bar9 ().fn (); });
157 bar9 ().fn (); /* { dg-warning "ignoring return value of" } */
158 (void) bar9 ().fn (); /* { dg-warning "ignoring return value of" } */
159 bar9 ().fn (), bar (); /* { dg-warning "ignoring return value of" } */
160 if ((k
? check1
: check10
) ())
162 i
+= (k
? check1
: check10
) ();
163 i
+= ({ (k
? check1
: check10
) (); });
164 (k
? check1
: check10
) (); /* { dg-warning "ignoring return value of" } */
165 (void) (k
? check1
: check10
) (); /* { dg-warning "ignoring return value of" } */
166 (k
? check1
: check10
) (), bar (); /* { dg-warning "ignoring return value of" } */
167 if ((k
? check3
: check11
) ())
169 i
+= (k
? check3
: check11
) ();
170 i
+= ({ (k
? check3
: check11
) (); });
171 (k
? check3
: check11
) (); /* { dg-warning "ignoring return value of" } */
172 (void) (k
? check3
: check11
) (); /* { dg-warning "ignoring return value of" } */
173 (k
? check3
: check11
) (), bar (); /* { dg-warning "ignoring return value of" } */
177 i
+= ({ pcheck1 (); });
178 pcheck1 (); /* { dg-warning "ignoring return value of" } */
179 (void) pcheck1 (); /* { dg-warning "ignoring return value of" } */
180 pcheck1 (), bar (); /* { dg-warning "ignoring return value of" } */
184 i
+= ({ pcheck3 (); });
185 pcheck3 (); /* { dg-warning "ignoring return value of" } */
186 (void) pcheck3 (); /* { dg-warning "ignoring return value of" } */
187 pcheck3 (), bar (); /* { dg-warning "ignoring return value of" } */