Skip analyzer strndup test on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / gcc.dg / c23-stdarg-4.c
blobcbbd9ef08ef1807aca5ce452b0966d56e33615a2
1 /* Test C23 variadic functions with no named parameters, or last named
2 parameter with a declaration not allowed in C17. Execution tests. */
3 /* { dg-do run } */
4 /* { dg-options "-std=c23 -pedantic-errors" } */
6 #include <stdarg.h>
8 extern void abort (void);
9 extern void exit (int);
11 double
12 f (...)
14 va_list ap;
15 va_start (ap);
16 double ret = va_arg (ap, int);
17 ret += va_arg (ap, double);
18 ret += va_arg (ap, int);
19 ret += va_arg (ap, double);
20 va_end (ap);
21 return ret;
24 void
25 g (...)
27 va_list ap;
28 va_start (ap, random ! ignored, ignored ** text);
29 for (int i = 0; i < 10; i++)
30 if (va_arg (ap, double) != i)
31 abort ();
32 va_end (ap);
35 void
36 h1 (register int x, ...)
38 va_list ap;
39 va_start (ap);
40 for (int i = 0; i < 10; i++)
42 if (va_arg (ap, double) != i)
43 abort ();
44 i++;
45 if (va_arg (ap, int) != i)
46 abort ();
48 va_end (ap);
51 void
52 h2 (int x(), ...)
54 va_list ap;
55 va_start (ap);
56 for (int i = 0; i < 10; i++)
58 if (va_arg (ap, double) != i)
59 abort ();
60 i++;
61 if (va_arg (ap, int) != i)
62 abort ();
64 va_end (ap);
67 void
68 h3 (int x[10], ...)
70 va_list ap;
71 va_start (ap);
72 for (int i = 0; i < 10; i++)
74 if (va_arg (ap, double) != i)
75 abort ();
76 i++;
77 if (va_arg (ap, int) != i)
78 abort ();
80 va_end (ap);
83 void
84 h4 (char x, ...)
86 va_list ap;
87 va_start (ap);
88 for (int i = 0; i < 10; i++)
90 if (va_arg (ap, double) != i)
91 abort ();
92 i++;
93 if (va_arg (ap, int) != i)
94 abort ();
96 va_end (ap);
99 void
100 h5 (float x, ...)
102 va_list ap;
103 va_start (ap);
104 for (int i = 0; i < 10; i++)
106 if (va_arg (ap, double) != i)
107 abort ();
108 i++;
109 if (va_arg (ap, int) != i)
110 abort ();
112 va_end (ap);
115 void
116 h6 (volatile long x, ...)
118 va_list ap;
119 va_start (ap);
120 for (int i = 0; i < 10; i++)
122 if (va_arg (ap, double) != i)
123 abort ();
124 i++;
125 if (va_arg (ap, int) != i)
126 abort ();
128 va_end (ap);
131 struct s { char c[1000]; };
133 void
134 h7 (volatile struct s x, ...)
136 va_list ap;
137 va_start (ap);
138 for (int i = 0; i < 10; i++)
140 if (va_arg (ap, double) != i)
141 abort ();
142 i++;
143 if (va_arg (ap, int) != i)
144 abort ();
146 va_end (ap);
150 main ()
152 if (f (1, 2.0, 3, 4.0) != 10.0)
153 abort ();
154 g (0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);
155 g (0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f);
156 h1 (0, 0.0, 1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9);
157 h2 (0, 0.0, 1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9);
158 h3 (0, 0.0, 1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9);
159 h4 (0, 0.0, 1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9);
160 h5 (0, 0.0, 1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9);
161 h6 (0, 0.0, 1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9);
162 h7 ((struct s) {}, 0.0, 1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9);
163 exit (0);