1 /* $NetBSD: d_c99_compound_literal_comma.c,v 1.4 2023/07/07 19:45:22 rillig Exp $ */
2 # 3 "d_c99_compound_literal_comma.c"
3
4 /*-
5 * Ensure that compound literals can be parsed.
6 *
7 * C99 6.5.2 "Postfix operators" for the syntax.
8 * C99 6.5.2.5 "Compound literals" for the semantics.
9 */
10
11 /* lint1-extra-flags: -X 351 */
12
13 struct point {
14 int x;
15 int y;
16 };
17
18 struct point
point_abs(struct point point)19 point_abs(struct point point)
20 {
21 /* No designators, no trailing comma. */
22 if (point.x >= 0 && point.y >= 0)
23 return (struct point){ point.x, point.y };
24
25 /* Designators, no trailing comma. */
26 if (point.x >= 0)
27 return (struct point){ .x = point.x, .y = -point.y };
28
29 /* No designators, trailing comma. */
30 if (point.y >= 0)
31 return (struct point){ point.x, point.y, };
32
33 /* Designators, trailing comma. */
34 return (struct point){ .x = point.x, .y = -point.y, };
35 }
36