Module Name:    src
Committed By:   rillig
Date:           Sat Apr 22 15:14:37 UTC 2023

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_159.c
        src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: do not warn about parenthesized assignment in controlling expr

Same as for GCC and Clang.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_159.c
cvs rdiff -u -r1.514 -r1.515 src/usr.bin/xlint/lint1/tree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_159.c
diff -u src/tests/usr.bin/xlint/lint1/msg_159.c:1.4 src/tests/usr.bin/xlint/lint1/msg_159.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_159.c:1.4	Wed Jul  6 21:13:13 2022
+++ src/tests/usr.bin/xlint/lint1/msg_159.c	Sat Apr 22 15:14:37 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_159.c,v 1.4 2022/07/06 21:13:13 rillig Exp $	*/
+/*	$NetBSD: msg_159.c,v 1.5 2023/04/22 15:14:37 rillig Exp $	*/
 # 3 "msg_159.c"
 
 // Test for message: assignment in conditional context [159]
@@ -12,6 +12,11 @@ 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";
 
@@ -27,10 +32,10 @@ example(int a, int b)
 		return "assignment, not parenthesized";
 
 	/*
-	 * XXX: GCC has the convention that an assignment that is
-	 * parenthesized is intended as an assignment.
+	 * GCC established the convention that an assignment that is
+	 * parenthesized is intended as an assignment, so don't warn about
+	 * that case.
 	 */
-	/* expect+1: warning: assignment in conditional context [159] */
 	if ((a = b))
 		return "assignment, parenthesized";
 

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.514 src/usr.bin/xlint/lint1/tree.c:1.515
--- src/usr.bin/xlint/lint1/tree.c:1.514	Sat Apr 22 09:39:14 2023
+++ src/usr.bin/xlint/lint1/tree.c	Sat Apr 22 15:14:37 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.514 2023/04/22 09:39:14 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.515 2023/04/22 15:14:37 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: tree.c,v 1.514 2023/04/22 09:39:14 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.515 2023/04/22 15:14:37 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -4372,7 +4372,7 @@ expr(tnode_t *tn, bool vctx, bool cond, 
 		check_statement_reachable();
 
 	check_expr_misc(tn, vctx, cond, !cond, false, false, false);
-	if (tn->tn_op == ASSIGN) {
+	if (tn->tn_op == ASSIGN && !tn->tn_parenthesized) {
 		if (hflag && cond)
 			/* assignment in conditional context */
 			warning(159);

Reply via email to