Module Name:    src
Committed By:   rillig
Date:           Mon Jan  4 22:41:56 UTC 2021

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

Log Message:
lint: finish the comments in check_precedence_confusion


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_169.c
cvs rdiff -u -r1.128 -r1.129 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_169.c
diff -u src/tests/usr.bin/xlint/lint1/msg_169.c:1.2 src/tests/usr.bin/xlint/lint1/msg_169.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_169.c:1.2	Mon Jan  4 15:52:51 2021
+++ src/tests/usr.bin/xlint/lint1/msg_169.c	Mon Jan  4 22:41:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_169.c,v 1.2 2021/01/04 15:52:51 rillig Exp $	*/
+/*	$NetBSD: msg_169.c,v 1.3 2021/01/04 22:41:56 rillig Exp $	*/
 # 3 "msg_169.c"
 
 // Test for message: precedence confusion possible: parenthesize! [169]
@@ -146,5 +146,6 @@ expected_precedence(int a, int b, int c)
 	ok = a + b * c;
 }
 
-// TODO: add a test with unsigned long instead of unsigned, to demonstrate
-//  that the typo in
+// TODO: add a test with unsigned long instead of unsigned, trying to
+//  demonstrate that the typo in check_precedence_confusion actually has an
+//  effect.

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.128 src/usr.bin/xlint/lint1/tree.c:1.129
--- src/usr.bin/xlint/lint1/tree.c:1.128	Mon Jan  4 22:33:47 2021
+++ src/usr.bin/xlint/lint1/tree.c	Mon Jan  4 22:41:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.128 2021/01/04 22:33:47 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.129 2021/01/04 22:41:56 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.128 2021/01/04 22:33:47 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.129 2021/01/04 22:41:56 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -4016,6 +4016,19 @@ check_precedence_confusion(tnode_t *tn)
 		 * Before fixing this though, there should be a unit test
 		 * that demonstrates an actual change in behavior when this
 		 * bug gets fixed.
+		 *
+		 * Right now, the condition is always false.  To make it true
+		 * after fixing the typo, the right-hand operand must be an
+		 * explicit cast or an implicit conversion that is
+		 * parenthesized.  For the right-hand operand itself, this
+		 * would already be done using the line below the loop.
+		 *
+		 * To make a difference, the right-hand operand must not be
+		 * parenthesized, but its indirect cast or conversion must be.
+		 *
+		 * An implicit conversion is never parenthesized.  Therefore
+		 * this must be a cast that is later converted, to build a
+		 * chain.
 		 */
 		for (rn = tn->tn_right; tn->tn_op == CVT; rn = rn->tn_left)
 			rparn |= rn->tn_parenthesized;

Reply via email to