Module Name:    src
Committed By:   rillig
Date:           Sat Jan 16 18:48:52 UTC 2021

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

Log Message:
lint: add missing warning for bool() == int


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
cvs rdiff -u -r1.159 -r1.160 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/d_c99_bool_strict.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.11 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.12
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.11	Sat Jan 16 17:54:22 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c	Sat Jan 16 18:48:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool_strict.c,v 1.11 2021/01/16 17:54:22 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict.c,v 1.12 2021/01/16 18:48:52 rillig Exp $	*/
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -710,8 +710,8 @@ query_flag_from_enum_bit_set(enum Flags 
 }
 
 
-bool
+void
 strict_bool_operator_eq_bool_int(void)
 {
-	return strict_bool_conversion_return_false() == 0; /* TODO: expect */
+	(void)(strict_bool_conversion_return_false() == 0); /* expect: 107 */
 }

Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.8 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.9
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.8	Sat Jan 16 16:03:47 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp	Sat Jan 16 18:48:52 2021
@@ -141,3 +141,4 @@ d_c99_bool_strict.c(662): operands of '=
 d_c99_bool_strict.c(670): operands of '=' have incompatible types (_Bool != int) [107]
 d_c99_bool_strict.c(677): operands of '=' have incompatible types (_Bool != int) [107]
 d_c99_bool_strict.c(652): warning: argument flags unused in function strict_bool_bitwise_and_enum [231]
+d_c99_bool_strict.c(716): operands of '==' have incompatible types (_Bool != int) [107]

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.159 src/usr.bin/xlint/lint1/tree.c:1.160
--- src/usr.bin/xlint/lint1/tree.c:1.159	Sat Jan 16 18:46:59 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sat Jan 16 18:48:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.159 2021/01/16 18:46:59 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.160 2021/01/16 18:48:52 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.159 2021/01/16 18:46:59 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.160 2021/01/16 18:48:52 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1111,6 +1111,21 @@ typeok_strict_bool_assign(op_t op, int a
 }
 
 /*
+ * Whether the operator can handle (bool, bool) as well as (scalar, scalar),
+ * but not mixtures between the two type classes.
+ */
+static bool
+needs_compatible_types(op_t op)
+{
+	return op == EQ || op == NE ||
+	       op == AND || op == XOR || op == OR ||
+	       op == COLON ||
+	       op == ASSIGN || op == ANDASS || op == XORASS || op == ORASS ||
+	       op == RETURN ||
+	       op == FARG;
+}
+
+/*
  * In strict bool mode, check whether the types of the operands match the
  * operator.
  */
@@ -1132,7 +1147,7 @@ typeok_scalar_strict_bool(op_t op, const
 		rt = NOTSPEC;
 	}
 
-	if (op == ASSIGN || op == FARG || op == RETURN || op == COLON)
+	if (needs_compatible_types(op))
 		return typeok_strict_bool_assign(op, arg, ln, lt, rn, rt);
 
 	if (mp->m_takes_only_bool || op == QUEST) {

Reply via email to