blob: ff8be370c4659daa8c9fd26d28b52a7775f76804 (
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
|
/* $NetBSD: msg_323.c,v 1.5 2023/03/28 14:44:35 rillig Exp $ */
# 3 "msg_323.c"
// Test for message: continue in 'do ... while (0)' loop [323]
/* lint1-extra-flags: -X 351 */
void println(const char *);
/*
* In simple cases of a do-while-0 loop, the statements 'break' and
* 'continue' have the same effect, and 'break' is much more common.
*
* This is also covered by Clang-Tidy.
*/
void
simple_case(const char *p)
{
do {
if (p[0] == '+')
break;
if (p[1] == '-')
continue;
println("no sign");
/* expect+1: error: continue in 'do ... while (0)' loop [323] */
} while (0);
}
/*
* If there is a 'switch' statement inside the do-while-0 loop, the 'break'
* statement is tied to the 'switch' statement instead of the loop.
*/
void
nested_switch(const char *p)
{
do {
switch (*p) {
case 'a':
continue; /* leaves the 'do while 0' */
case 'b':
break; /* leaves the 'switch' */
}
println("b");
/* XXX: Is that really worth an error? */
/* expect+1: error: continue in 'do ... while (0)' loop [323] */
} while (0);
}
/*
* In a nested loop, the 'continue' statement is bound to the inner loop,
* thus no warning.
*/
void
nested_for(void)
{
do {
for (int i = 0; i < 6; i++) {
if (i < 3)
continue;
}
} while (0);
}
|