lsym_rbrace.c revision 1.4
1/* $NetBSD: lsym_rbrace.c,v 1.4 2022/04/24 09:04:12 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/* $ FIXME: Each '{' must be properly indented. */
47{{{
48			body();
49}
50}
51}
52//indent end
53
54
55/* Compound literal */
56//indent input
57struct point
58origin(void)
59{
60	return (struct point){
61		.x = 0,
62		.y = 0,
63	};
64}
65//indent end
66
67//indent run
68struct point
69origin(void)
70{
71	return (struct point){
72		.x = 0,
73/* $ FIXME: All initializers must be indented to the same level. */
74			.y = 0,
75	};
76}
77//indent end
78