blob: 51692f37ad43c639ed1f17b7178236130cb1388d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
/* $NetBSD: opt_bad.c,v 1.12 2023/06/26 14:54:40 rillig Exp $ */
/*
* Tests for the options '-bad' and '-nbad'.
*
* The option '-bad' forces a blank line after every block of declarations.
* It only affects declarations of local variables. It does not affect
* file-scoped declarations or definitions.
*
* The option '-nbad' leaves everything as is.
*/
/* Test global declarations. */
//indent input
int global_variable;
void function_declaration(void);
#if 0
#endif
/* comment */
//indent end
//indent run-equals-input -bad
//indent run-equals-input -nbad
/* See FreeBSD r303599. */
//indent input
#if defined(__i386__)
int a;
#elif defined(__amd64__)
int b;
#else
#error "Port me"
#endif
//indent end
//indent run -bad
#if defined(__i386__)
int a;
#elif defined(__amd64__)
int b;
#else
#error "Port me"
#endif
//indent end
/* Test local declarations. */
//indent input
void function_definition(void) {
int local_variable;
function_call();
int local_variable_after_statement;
function_call();
}
//indent end
//indent run -bad
void
function_definition(void)
{
int local_variable;
function_call();
int local_variable_after_statement;
function_call();
}
//indent end
//indent run -nbad
void
function_definition(void)
{
int local_variable;
/* $ No blank line here. */
function_call();
int local_variable_after_statement;
/* $ No blank line here. */
function_call();
}
//indent end
/*
* A comment after a declaration does not change whether there should be a
* blank line below the declaration.
*/
//indent input
void
comments(void)
{
int local_var_1; /* comment */
int local_var_2; /* comment */
/* comment line */
function_call();
}
//indent end
//indent run -ldi0 -bad
void
comments(void)
{
int local_var_1; /* comment */
int local_var_2; /* comment */
// $ Indent does not look ahead much, so it doesn't know whether this comment
// $ will be followed by a declaration or a statement.
/* comment line */
function_call();
}
//indent end
//indent run-equals-input -ldi0 -nbad
/*
* A declaration that has a braced initializer is still a declaration and
* therefore needs a blank line below.
*/
//indent input
void
initializer(void)
{
int local_var_init_1[] = {1};
int local_var_init_2[] = {1};
function_call();
}
void
initializer_with_blank(void)
{
int local_var_init_1[] = {1};
int local_var_init_2[] = {1};
function_call();
}
//indent end
//indent run -ldi0 -bad
void
initializer(void)
{
int local_var_init_1[] = {1};
int local_var_init_2[] = {1};
function_call();
}
void
initializer_with_blank(void)
{
int local_var_init_1[] = {1};
int local_var_init_2[] = {1};
function_call();
}
//indent end
//indent run-equals-input -ldi0 -nbad
//indent input
{
// $ The '}' in an initializer does not finish a declaration,
// $ only a semicolon does.
int decl1[2][2] = {
{1, 2},
{3, 4},
};
/* comment */
int decl2;
// $ If the declaration is followed by a '}' that terminates the block
// $ statement, * there is no need for a blank line before the '}'.
}
//indent end
//indent run-equals-input -bad -di0
|