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