msg_159.c revision 1.7
1/*	$NetBSD: msg_159.c,v 1.7 2023/07/07 19:45:22 rillig Exp $	*/
2# 3 "msg_159.c"
3
4// Test for message: assignment in conditional context [159]
5
6/* lint1-extra-flags: -h -X 351 */
7
8const char *
9example(int a, int b)
10{
11
12	if (a == b)
13		return "comparison, not parenthesized";
14
15	/*
16	 * Clang-Tidy marks a comparison with extra parentheses as an error,
17	 * expecting that assignments are parenthesized and comparisons
18	 * aren't.
19	 */
20	if ((a == b))
21		return "comparison, parenthesized";
22
23	if (
24# 25 "msg_159.c" 3 4
25	    (a == b)
26# 27 "msg_159.c"
27	    )
28		return "comparison, parenthesized, from system header";
29
30	/* expect+1: warning: assignment in conditional context [159] */
31	if (a = b)
32		return "assignment, not parenthesized";
33
34	/*
35	 * GCC established the convention that an assignment that is
36	 * parenthesized is intended as an assignment, so don't warn about
37	 * that case.
38	 */
39	if ((a = b))
40		return "assignment, parenthesized";
41
42	if ((a = b) != 0)
43		return "explicit comparison after assignment";
44
45	return "other";
46}
47