Module Name:    src
Committed By:   rillig
Date:           Sat Jun 24 17:50:31 UTC 2023

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

Log Message:
lint: don't warn about comparison between char and character constant


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/msg_230.c
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/msg_230_uchar.c
cvs rdiff -u -r1.529 -r1.530 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_230.c
diff -u src/tests/usr.bin/xlint/lint1/msg_230.c:1.12 src/tests/usr.bin/xlint/lint1/msg_230.c:1.13
--- src/tests/usr.bin/xlint/lint1/msg_230.c:1.12	Wed Feb 22 22:30:40 2023
+++ src/tests/usr.bin/xlint/lint1/msg_230.c	Sat Jun 24 17:50:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_230.c,v 1.12 2023/02/22 22:30:40 rillig Exp $	*/
+/*	$NetBSD: msg_230.c,v 1.13 2023/06/24 17:50:31 rillig Exp $	*/
 # 3 "msg_230.c"
 
 // Test for message: nonportable character comparison '%s' [230]
@@ -113,18 +113,12 @@ compare_greater(char c)
 		return;
 }
 
+/* Comparing a char expression with a character constant is always valid. */
 void
 compare_with_character_literal(char ch)
 {
-	/*
-	 * FIXME: These comparisons are portable since the character constant
-	 *  is interpreted using the type 'char' on the exact same platform
-	 *  as where the comparison takes place.
-	 */
-	/* expect+1: warning: nonportable character comparison '== -128' [230] */
 	if (ch == '\200')
 		return;
-	/* expect+1: warning: nonportable character comparison '== -1' [230] */
 	if (ch == '\377')
 		return;
 	if (ch == '\000')

Index: src/tests/usr.bin/xlint/lint1/msg_230_uchar.c
diff -u src/tests/usr.bin/xlint/lint1/msg_230_uchar.c:1.11 src/tests/usr.bin/xlint/lint1/msg_230_uchar.c:1.12
--- src/tests/usr.bin/xlint/lint1/msg_230_uchar.c:1.11	Mon Feb 27 21:59:14 2023
+++ src/tests/usr.bin/xlint/lint1/msg_230_uchar.c	Sat Jun 24 17:50:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_230_uchar.c,v 1.11 2023/02/27 21:59:14 rillig Exp $	*/
+/*	$NetBSD: msg_230_uchar.c,v 1.12 2023/06/24 17:50:31 rillig Exp $	*/
 # 3 "msg_230_uchar.c"
 
 // Test for message: nonportable character comparison '%s' [230]
@@ -117,18 +117,12 @@ compare_greater(char c)
 		return;
 }
 
+/* Comparing a char expression with a character constant is always valid. */
 void
 compare_with_character_literal(char ch)
 {
-	/*
-	 * FIXME: These comparisons are portable since the character constant
-	 *  is interpreted using the type 'char' on the exact same platform
-	 *  as where the comparison takes place.
-	 */
-	/* expect+1: warning: nonportable character comparison '== 128' [230] */
 	if (ch == '\200')
 		return;
-	/* expect+1: warning: nonportable character comparison '== 255' [230] */
 	if (ch == '\377')
 		return;
 	if (ch == '\000')

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.529 src/usr.bin/xlint/lint1/tree.c:1.530
--- src/usr.bin/xlint/lint1/tree.c:1.529	Sat Jun 24 08:11:12 2023
+++ src/usr.bin/xlint/lint1/tree.c	Sat Jun 24 17:50:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.529 2023/06/24 08:11:12 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.530 2023/06/24 17:50:31 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.529 2023/06/24 08:11:12 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.530 2023/06/24 17:50:31 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -580,6 +580,7 @@ static bool
 is_out_of_char_range(const tnode_t *tn)
 {
 	return tn->tn_op == CON &&
+	       !tn->tn_val->v_char_constant &&
 	       !(0 <= tn->tn_val->v_quad &&
 		 tn->tn_val->v_quad < 1 << (CHAR_SIZE - 1));
 }

Reply via email to