LWG 3035. std::allocator's constructors should be constexpr
[official-gcc.git] / gcc / testsuite / gcc.dg / c11-noreturn-2.c
blob58fafdb2e14d75f19a66c82b1eb71695903ccc5d
1 /* Test C11 _Noreturn. Test valid code using stdnoreturn.h. */
2 /* { dg-do run } */
3 /* { dg-options "-std=c11 -pedantic-errors" } */
5 #include <stdnoreturn.h>
7 extern int strcmp (const char *, const char *);
9 noreturn void exit (int);
10 noreturn void abort (void);
12 noreturn int f1 (void);
14 noreturn void f2 (void);
16 static void noreturn f3 (void) { exit (0); }
18 /* Returning from a noreturn function is undefined at runtime, not a
19 constraint violation, but recommended practice is to diagnose if
20 such a return appears possible. */
22 noreturn int
23 f4 (void)
25 return 1; /* { dg-warning "has a 'return' statement" } */
26 /* { dg-warning "does return" "second warning" { target *-*-* } .-1 } */
29 noreturn void
30 f5 (void)
32 return; /* { dg-warning "has a 'return' statement" } */
33 /* { dg-warning "does return" "second warning" { target *-*-* } .-1 } */
36 noreturn void
37 f6 (void)
39 } /* { dg-warning "does return" } */
41 noreturn void
42 f7 (int a)
44 if (a)
45 exit (0);
46 } /* { dg-warning "does return" } */
48 /* Declarations need not all have noreturn. */
50 void f2 (void);
52 void f8 (void);
53 noreturn void f8 (void);
55 /* Duplicate noreturn is OK. */
56 noreturn noreturn void noreturn f9 (void);
58 /* noreturn does not affect type compatibility. */
60 void (*fp) (void) = f5;
62 #ifndef noreturn
63 #error "noreturn not defined"
64 #endif
66 #define str(x) #x
67 #define xstr(x) str(x)
69 const char *s = xstr(noreturn);
71 int
72 main (void)
74 if (strcmp (s, "_Noreturn") != 0)
75 abort ();
76 exit (0);