Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: add missing warning for bool() == int
details: https://anonhg.NetBSD.org/src/rev/a1256fd0d1f8
branches: trunk
changeset: 979895:a1256fd0d1f8
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jan 16 18:48:52 2021 +0000
description:
lint: add missing warning for bool() == int
diffstat:
tests/usr.bin/xlint/lint1/d_c99_bool_strict.c | 6 +++---
tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp | 1 +
usr.bin/xlint/lint1/tree.c | 21 ++++++++++++++++++---
3 files changed, 22 insertions(+), 6 deletions(-)
diffs (77 lines):
diff -r 735cf24f7f85 -r a1256fd0d1f8 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c Sat Jan 16 18:46:59 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c Sat Jan 16 18:48:52 2021 +0000
@@ -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 @@
}
-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 */
}
diff -r 735cf24f7f85 -r a1256fd0d1f8 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp Sat Jan 16 18:46:59 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp Sat Jan 16 18:48:52 2021 +0000
@@ -141,3 +141,4 @@
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]
diff -r 735cf24f7f85 -r a1256fd0d1f8 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sat Jan 16 18:46:59 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sat Jan 16 18:48:52 2021 +0000
@@ -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 @@
}
/*
+ * 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 @@
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) {
Home |
Main Index |
Thread Index |
Old Index