PR c/81544 - attribute noreturn and warn_unused_result on the same function accepted
[official-gcc.git] / gcc / testsuite / gcc.dg / torture / pr42363.c
blobad0eac8ceed51efd6a35057415f2b33c7f7ef8c7
1 /* PR middle-end/pr42363, extended from the test for PR middle-end/37913. */
2 /* { dg-do compile } */
3 /* { dg-options "-g" } */
5 void foo (void) __attribute__ ((noreturn));
7 static int __attribute__ ((noreturn))
8 bar (void)
10 foo ();
13 int
14 baz (void)
16 int i = bar ();
17 return i + 1;
20 int fooz (void) __attribute__ ((noreturn));
22 static int __attribute__ ((noreturn))
23 bart (void)
25 return fooz (); /* { dg-warning "noreturn" } */
28 int bazr (void)
30 int i = bart ();
31 return i + 1;
34 static inline int
35 bard (void)
37 return fooz ();
40 int bizr (void)
42 int i, j;
44 i = j = bard ();
46 return i + 1;
49 /* This might be regarded as pure and folded, rather than inlined,
50 but because it's pure evil it's diagnosed and the noreturn attribute
51 is dropped. The const attribute is dropped as well because it's
52 mutually exclusive with pure. */
53 static int __attribute__ ((pure, const, noreturn))
54 barf (void) {
55 /* { dg-warning "ignoring attribute .const." "const" { target *-*-* } .-1 } */
56 /* { dg-warning "ignoring attribute .noreturn." "noreturn" { target *-*-* } .-2 } */
57 } /* { dg-warning "does return" } */
59 static int __attribute__ ((pure, const))
60 bark (void) { /* { dg-warning "ignoring attribute .const." } */
61 barf ();
64 int buzr (void)
66 int i, j;
68 i = j = bark () + bark ();
70 return i + 1;
73 int buzt (void)
75 int i, j;
77 i = j = barf () + barf ();
79 return i + 1;
82 void bust (void)
84 while (barf ())