1 /* Test C11 _Generic.  Valid uses.  */
2 /* { dg-do run } */
3 /* { dg-options "-std=c11 -pedantic-errors" } */
4 
5 _Noreturn extern void exit (int);
6 _Noreturn extern void abort (void);
7 
8 void
check(int n)9 check (int n)
10 {
11   if (n)
12     abort ();
13 }
14 
15 int
main(void)16 main (void)
17 {
18   int n = 0;
19 
20   check (_Generic (n++, int: 0));
21   /* _Generic should not evaluate its argument.  */
22   check (n);
23 
24   check (_Generic (n, double: n++, default: 0));
25   check (n);
26 
27   /* Qualifiers are removed for the purpose of type matching.  */
28   const int cn = 0;
29   check (_Generic (cn, int: 0, default: n++));
30   check (n);
31   check (_Generic ((const int) n, int: 0, default: n++));
32   check (n);
33 
34   /* Arrays decay to pointers.  */
35   int a[1];
36   const int ca[1];
37   check (_Generic (a, int *: 0, const int *: n++));
38   check (n);
39   check (_Generic (ca, const int *: 0, int *: n++));
40   check (n);
41 
42   /* Functions decay to pointers.  */
43   extern void f (void);
44   check (_Generic (f, void (*) (void): 0, default: n++));
45   check (n);
46 
47   /* _Noreturn is not part of the function type.  */
48   check (_Generic (&abort, void (*) (void): 0, default: n++));
49   check (n);
50 
51   /* Integer promotions do not occur.  */
52   short s;
53   check (_Generic (s, short: 0, int: n++));
54   check (n);
55 
56   exit (0);
57 }
58