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 test for using a bool as array...



details:   https://anonhg.NetBSD.org/src/rev/ff3fd01f166b
branches:  trunk
changeset: 959624:ff3fd01f166b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Feb 20 18:02:58 2021 +0000

description:
lint: add test for using a bool as array index in strict bool mode

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c   |  15 ++++++++++++++-
 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp |   1 +
 usr.bin/xlint/lint1/ops.def                     |   3 ++-
 3 files changed, 17 insertions(+), 2 deletions(-)

diffs (51 lines):

diff -r fd7426793a51 -r ff3fd01f166b tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sat Feb 20 17:44:39 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sat Feb 20 18:02:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_bool_strict.c,v 1.17 2021/01/17 23:00:41 rillig Exp $    */
+/*     $NetBSD: d_c99_bool_strict.c,v 1.18 2021/02/20 18:02:58 rillig Exp $    */
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -727,3 +727,16 @@
 
        (void)((s.flag = s.flag) != __lint_false);
 }
+
+void
+bool_as_array_index(bool cond)
+{
+       static const char *repr[] = { "no", "yes" };
+       /*
+        * The '+' in the error message reveals that lint internally
+        * translates 'arr[ind]' to '*(arr + ind)' in an early stage of
+        * parsing.
+        */
+       println(repr[cond]);            /* expect: 337 */
+       println(cond ? "yes" : "no");
+}
diff -r fd7426793a51 -r ff3fd01f166b tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sat Feb 20 17:44:39 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sat Feb 20 18:02:58 2021 +0000
@@ -146,3 +146,4 @@
 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]
+d_c99_bool_strict.c(740): right operand of '+' must not be bool [337]
diff -r fd7426793a51 -r ff3fd01f166b usr.bin/xlint/lint1/ops.def
--- a/usr.bin/xlint/lint1/ops.def       Sat Feb 20 17:44:39 2021 +0000
+++ b/usr.bin/xlint/lint1/ops.def       Sat Feb 20 18:02:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ops.def,v 1.15 2021/01/17 15:06:54 rillig Exp $ */
+/*     $NetBSD: ops.def,v 1.16 2021/02/20 18:02:58 rillig Exp $ */
 
 begin_ops()
 
@@ -20,6 +20,7 @@
 op(    UMINUS, "-",             , , , , , ,1, ,1,1, , , ,1, , , , ,1,1,1)
 op(    INDIR,  "*",             , , , , , , , , ,1, , , , , , , , , , ,1)
 op(    ADDR,   "&",             , ,1, , , , , , , , , , , , , , , , , ,1)
+/* the operator 'arr[ind]' is translated to '*(arr + ind)' during parsing. */
 
 /*     name    repr            b l b o i c a s f v t b s l r p c e e = act */
 op(    MULT,   "*",            1, , , , , ,1, ,1,1, ,1, , ,1, , , ,1,1,1)



Home | Main Index | Thread Index | Old Index