opt_ldi.c revision 1.3
1/* $NetBSD: opt_ldi.c,v 1.3 2021/11/20 16:54:17 rillig Exp $ */
2/* $FreeBSD$ */
3
4/*
5 * Tests for the option '-ldi', which specifies where the variable names of
6 * locally declared variables are placed.
7 *
8 * See also:
9 *	opt_di.c
10 */
11
12#indent input
13int global;
14
15void
16function(void)
17{
18	int local;
19}
20#indent end
21
22#indent run -ldi0
23int		global;
24
25void
26function(void)
27{
28	int local;
29}
30#indent end
31
32#indent run -ldi8
33int		global;
34
35void
36function(void)
37{
38	int	local;
39}
40#indent end
41
42#indent run -ldi24
43int		global;
44
45void
46function(void)
47{
48	int			local;
49}
50#indent end
51
52
53/*
54 * A variable that has an ad-hoc struct/union/enum type does not need to be
55 * indented to the right of the keyword 'struct', it only needs a single space
56 * of indentation.
57 *
58 * Before NetBSD indent.c 1.151 from 2021-10-24, the indentation depended on
59 * the length of the keyword 'struct', 'union' or 'enum', together with type
60 * qualifiers like 'const' or the storage class like 'static'.
61 */
62#indent input
63{
64	struct {
65		int member;
66	} var = {
67		3,
68	};
69}
70#indent end
71
72/*
73 * Struct members use '-di' for indentation, no matter whether they are
74 * declared globally or locally.
75 */
76#indent run -ldi0
77{
78	struct {
79		int		member;
80	} var = {
81		3,
82	};
83}
84#indent end
85
86#indent run -ldi16
87{
88	struct {
89		int		member;
90	}		var = {
91		3,
92	};
93}
94#indent end
95