fmt_block.c revision 1.6
1/* $NetBSD: fmt_block.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
2
3/*
4 * Tests for formatting blocks of statements and declarations.
5 *
6 * See also:
7 *	lsym_lbrace.c
8 *	psym_stmt.c
9 *	psym_stmt_list.c
10 */
11
12//indent input
13void
14function(void)
15{
16	if (true) {
17
18	}
19
20	{
21		print("block");
22	}
23}
24//indent end
25
26/*
27 * Before 2023-05-11, indent incorrectly merged the '} {' into a single line,
28 * even though they are completely unrelated.
29 */
30//indent run-equals-input
31
32
33/*
34 * Two adjacent blocks must not be merged.  They are typically used in C90 and
35 * earlier to declare local variables with a limited scope.
36 */
37//indent input
38void
39function(void)
40{
41	{}{}
42}
43//indent end
44
45//indent run
46void
47function(void)
48{
49	{
50/* $ FIXME: '{' must start a new line. */
51	} {
52	}
53}
54//indent end
55
56/*
57 * The buggy behavior only occurs with the default setting '-br', which
58 * places an opening brace to the right of the preceding 'if (expr)' or
59 * similar statements.
60 */
61//indent run -bl
62void
63function(void)
64{
65	{
66	}
67	{
68	}
69}
70//indent end
71