Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint1 lint: explain missing error for _B...
details: https://anonhg.NetBSD.org/src/rev/26027d1e8932
branches: trunk
changeset: 1017813:26027d1e8932
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jan 10 13:17:24 2021 +0000
description:
lint: explain missing error for _Bool constant expressions
diffstat:
tests/usr.bin/xlint/lint1/d_c99_bool.c | 19 ++++++++++++++-----
tests/usr.bin/xlint/lint1/d_c99_bool.exp | 22 +++++++++++-----------
2 files changed, 25 insertions(+), 16 deletions(-)
diffs (66 lines):
diff -r 1674078703bd -r 26027d1e8932 tests/usr.bin/xlint/lint1/d_c99_bool.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool.c Sun Jan 10 12:46:38 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool.c Sun Jan 10 13:17:24 2021 +0000
@@ -1,5 +1,5 @@
-/* $NetBSD: d_c99_bool.c,v 1.4 2021/01/10 12:46:38 rillig Exp $ */
-# 3 "d_bool.c"
+/* $NetBSD: d_c99_bool.c,v 1.5 2021/01/10 13:17:24 rillig Exp $ */
+# 3 "d_c99_bool.c"
/*
* C99 6.3.1.2 says: "When any scalar value is converted to _Bool, the result
@@ -9,7 +9,7 @@
* invoke undefined behavior.
*/
-/* Below, the wrong assertions produce warning 20. */
+/* Below, each wrong assertion produces "negative array dimension" [20]. */
int int_0_converts_to_false[(_Bool)0 ? -1 : 1];
int int_0_converts_to_true_[(_Bool)0 ? 1 : -1];
@@ -26,8 +26,17 @@
int null_pointer_converts_to_false[(_Bool)(void *)0 ? -1 : 1];
int null_pointer_converts_to_true_[(_Bool)(void *)0 ? 1 : -1];
-int nonnull_pointer_converts_to_false[(_Bool)"not null" ? -1 : 1];
-int nonnull_pointer_converts_to_true_[(_Bool)"not null" ? 1 : -1];
+/*
+ * XXX: lint does not treat the address of a global variable as a constant
+ * expression. This goes against C99 6.6p7 but is probably not too relevant
+ * in practice.
+ *
+ * The call to constant(tn, 0) defaults to 1, then. This is why neither of
+ * the following array declarations generates an error message.
+ */
+char ch;
+int nonnull_pointer_converts_to_false[(_Bool)&ch ? -1 : 1];
+int nonnull_pointer_converts_to_true_[(_Bool)&ch ? 1 : -1];
int double_minus_1_0_converts_to_false[(_Bool)-1.0 ? -1 : 1];
int double_minus_1_0_converts_to_true_[(_Bool)-1.0 ? 1 : -1];
diff -r 1674078703bd -r 26027d1e8932 tests/usr.bin/xlint/lint1/d_c99_bool.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool.exp Sun Jan 10 12:46:38 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool.exp Sun Jan 10 13:17:24 2021 +0000
@@ -1,11 +1,11 @@
-d_bool.c(15): negative array dimension (-1) [20]
-d_bool.c(17): negative array dimension (-1) [20]
-d_bool.c(20): negative array dimension (-1) [20]
-d_bool.c(23): negative array dimension (-1) [20]
-d_bool.c(27): negative array dimension (-1) [20]
-d_bool.c(32): negative array dimension (-1) [20]
-d_bool.c(35): negative array dimension (-1) [20]
-d_bool.c(39): negative array dimension (-1) [20]
-d_bool.c(42): negative array dimension (-1) [20]
-d_bool.c(45): negative array dimension (-1) [20]
-d_bool.c(48): negative array dimension (-1) [20]
+d_c99_bool.c(15): negative array dimension (-1) [20]
+d_c99_bool.c(17): negative array dimension (-1) [20]
+d_c99_bool.c(20): negative array dimension (-1) [20]
+d_c99_bool.c(23): negative array dimension (-1) [20]
+d_c99_bool.c(27): negative array dimension (-1) [20]
+d_c99_bool.c(41): negative array dimension (-1) [20]
+d_c99_bool.c(44): negative array dimension (-1) [20]
+d_c99_bool.c(48): negative array dimension (-1) [20]
+d_c99_bool.c(51): negative array dimension (-1) [20]
+d_c99_bool.c(54): negative array dimension (-1) [20]
+d_c99_bool.c(57): negative array dimension (-1) [20]
Home |
Main Index |
Thread Index |
Old Index