blob: 37216dff05228e536add262a4626787c677ca292 (
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
|
/* $NetBSD: msg_159.c,v 1.7 2023/07/07 19:45:22 rillig Exp $ */
# 3 "msg_159.c"
// Test for message: assignment in conditional context [159]
/* lint1-extra-flags: -h -X 351 */
const char *
example(int a, int b)
{
if (a == b)
return "comparison, not parenthesized";
/*
* Clang-Tidy marks a comparison with extra parentheses as an error,
* expecting that assignments are parenthesized and comparisons
* aren't.
*/
if ((a == b))
return "comparison, parenthesized";
if (
# 25 "msg_159.c" 3 4
(a == b)
# 27 "msg_159.c"
)
return "comparison, parenthesized, from system header";
/* expect+1: warning: assignment in conditional context [159] */
if (a = b)
return "assignment, not parenthesized";
/*
* GCC established the convention that an assignment that is
* parenthesized is intended as an assignment, so don't warn about
* that case.
*/
if ((a = b))
return "assignment, parenthesized";
if ((a = b) != 0)
return "explicit comparison after assignment";
return "other";
}
|