1/* $NetBSD: lsym_rbrace.c,v 1.7 2023/06/08 06:47:14 rillig Exp $ */
2
3/*
4 * Tests for the token lsym_rbrace, which represents a '}' in these contexts:
5 *
6 * In an initializer, '}' ends an inner group of initializers, usually to
7 * initialize a nested struct, union or array.
8 *
9 * In a function body, '}' ends a block.
10 *
11 * In an expression like '(type){...}', '}' ends a compound literal, which is
12 * typically used in an assignment to a struct or array.
13 *
14 * In macro arguments, a '}' is an ordinary character, it does not need to be
15 * balanced.  This is in contrast to '(' and ')', which must be balanced.
16 *
17 * TODO: try to split this token into lsym_rbrace_block and lsym_rbrace_init.
18 *
19 * See also:
20 *	lsym_lbrace.c
21 */
22
23/* Brace level in an initializer */
24//indent input
25void
26function(void)
27{
28	struct person	p = {
29		.name = "Name",
30		.age = {{{35}}},	/* C11 6.7.9 allows this. */
31	};
32}
33//indent end
34
35//indent run-equals-input
36
37
38/* Begin of a block of statements */
39//indent input
40void function(void) {{{ body(); }}}
41//indent end
42
43//indent run
44void
45function(void)
46{
47	{
48		{
49			body();
50		}
51	}
52}
53//indent end
54
55
56/* Compound literal */
57//indent input
58struct point
59origin(void)
60{
61	return (struct point){
62		.x = 0,
63		.y = 0,
64	};
65}
66//indent end
67
68//indent run-equals-input
69
70
71//indent input
72{
73int numbers[][] = {
74{11},
75{21},
76{31},
77};
78int numbers[][] = {{11},
79{21},
80{31},
81};
82}
83//indent end
84
85//indent run -di0
86{
87	int numbers[][] = {
88		{11},
89		{21},
90		{31},
91	};
92	int numbers[][] = {{11},
93	// $ FIXME: Must be indented.
94	{21},
95	{31},
96	};
97}
98//indent end
99