1/* Check for various valid and erroneous "noreturn" cases. */
2/* { dg-do compile } */
3/* { dg-options "-O2 -Wmissing-noreturn" } */
4
5extern void exit (int);
6
7extern void foo1(void) __attribute__ ((__noreturn__));
8void
9foo1(void)
10{
11} /* { dg-warning "'noreturn' function does return" "detect falling off end of noreturn" } */
12
13extern void foo2(void) __attribute__ ((__noreturn__));
14void
15foo2(void)
16{
17  exit(0);
18} /* { dg-bogus "warning:" "this function should not get any warnings" } */
19
20extern void foo3(void);
21void
22foo3(void)
23{
24} /* { dg-bogus "warning:" "this function should not get any warnings" } */
25
26extern void foo4(void);
27void
28foo4(void) /* { dg-warning "candidate for attribute 'noreturn'" "detect noreturn candidate" } */
29{
30  exit(0);
31}
32
33extern void foo5(void) __attribute__ ((__noreturn__));
34void
35foo5(void)
36{
37  return; /* { dg-warning "'noreturn' has a 'return' statement" "detect invalid return" } */
38}         /* { dg-warning "function does return" "detect return from noreturn" { target c } 37 } */
39
40extern void foo6(void);
41void
42foo6(void)
43{
44  return;
45} /* { dg-bogus "warning:" "this function should not get any warnings" } */
46
47extern void foo7(void);
48void
49foo7(void)
50{
51  foo6();
52} /* { dg-bogus "warning:" "this function should not get any warnings" } */
53
54extern void foo8(void) __attribute__ ((__noreturn__));
55void
56foo8(void)
57{
58  foo7();
59} /* { dg-warning "'noreturn' function does return" "detect return from tail call" } */
60