fmt_block.c revision 1.4
1/* $NetBSD: fmt_block.c,v 1.4 2022/04/24 09:04:12 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//indent run
27void
28function(void)
29{
30	if (true) {
31
32/* $ FIXME: indent must not merge these braces. */
33	} {
34/* $ FIXME: the following empty line was not in the input. */
35
36		print("block");
37	}
38}
39//indent end
40
41
42/*
43 * Two adjacent blocks must not be merged.  They are typically used in C90 and
44 * earlier to declare local variables with a limited scope.
45 */
46//indent input
47void
48function(void)
49{
50	{}{}
51}
52//indent end
53
54//indent run
55void
56function(void)
57{
58	{
59/* $ FIXME: '{' must start a new line. */
60	} {
61	}
62}
63//indent end
64
65/*
66 * The buggy behavior only occurs with the default setting '-br', which
67 * places an opening brace to the right of the preceding 'if (expr)' or
68 * similar statements.
69 */
70//indent run -bl
71void
72function(void)
73{
74	{
75	}
76	{
77	}
78}
79//indent end
80