Module Name: src Committed By: rillig Date: Sat Feb 20 18:02:58 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: ops.def Log Message: lint: add test for using a bool as array index in strict bool mode To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c cvs rdiff -u -r1.15 -r1.16 \ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp cvs rdiff -u -r1.15 -r1.16 src/usr.bin/xlint/lint1/ops.def 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.17 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.18 --- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c:1.17 Sun Jan 17 23:00:41 2021 +++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c Sat Feb 20 18:02:58 2021 @@ -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 @@ strict_bool_assign_bit_field_then_compar (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"); +} 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.15 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.16 --- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp:1.15 Sun Jan 17 23:00:41 2021 +++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp Sat Feb 20 18:02:58 2021 @@ -146,3 +146,4 @@ d_c99_bool_strict.c(670): operands of '= 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] Index: src/usr.bin/xlint/lint1/ops.def diff -u src/usr.bin/xlint/lint1/ops.def:1.15 src/usr.bin/xlint/lint1/ops.def:1.16 --- src/usr.bin/xlint/lint1/ops.def:1.15 Sun Jan 17 15:06:54 2021 +++ src/usr.bin/xlint/lint1/ops.def Sat Feb 20 18:02:58 2021 @@ -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( UPLUS, "+", , , , , , ,1, ,1,1, , 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)