Module Name: src Committed By: rillig Date: Tue Jan 12 20:42:01 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: d_c99_bool_strict.c d_c99_bool_strict.exp src/usr.bin/xlint/common: externs.h src/usr.bin/xlint/lint1: cgram.y err.c externs1.h func.c main1.c op.h oper.c ops.def tree.c src/usr.bin/xlint/lint2: main2.c src/usr.bin/xlint/xlint: lint.1 xlint.c Added Files: src/tests/usr.bin/xlint: check-expect.lua Log Message: lint: add new check for strict bool mode In strict bool mode, bool is considered incompatible with all other scalar types, just as in Java, C#, Pascal. The controlling expressions in if statements, while loops, for loops and the '?:' operator must be of type bool. The logical operators work on bool instead of int, the bitwise operators accept both integer and bool. The arithmetic operators don't accept bool. Since <stdbool.h> implements bool using C preprocessor macros instead of predefining the identifiers "true" and "false", the integer constants 0 and 1 may be used in all contexts that require a bool expression. Except from these, no implicit conversion between bool and scalar types is allowed. See usr.bin/tests/xlint/lint1/d_c99_bool_strict.c for more details. The command line option -T has been chosen because all obvious choices (-b or -B for bool, -s or -S for strict) are already in use. The -T may stand for "types are checked strictly". The default behavior of lint doesn't change. The strict bool check is purely optional. An example program for strict bool mode is usr.bin/make, which has been using explicit comparisons such as p != NULL, ch != '\0' or n > 0 in most places for a long time now, even before the refactoring in 2020. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/check-expect.lua cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp cvs rdiff -u -r1.12 -r1.13 src/usr.bin/xlint/common/externs.h cvs rdiff -u -r1.138 -r1.139 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.65 -r1.66 src/usr.bin/xlint/lint1/err.c cvs rdiff -u -r1.54 -r1.55 src/usr.bin/xlint/lint1/externs1.h cvs rdiff -u -r1.56 -r1.57 src/usr.bin/xlint/lint1/func.c cvs rdiff -u -r1.33 -r1.34 src/usr.bin/xlint/lint1/main1.c cvs rdiff -u -r1.11 -r1.12 src/usr.bin/xlint/lint1/op.h cvs rdiff -u -r1.2 -r1.3 src/usr.bin/xlint/lint1/oper.c cvs rdiff -u -r1.9 -r1.10 src/usr.bin/xlint/lint1/ops.def cvs rdiff -u -r1.150 -r1.151 src/usr.bin/xlint/lint1/tree.c cvs rdiff -u -r1.10 -r1.11 src/usr.bin/xlint/lint2/main2.c cvs rdiff -u -r1.41 -r1.42 src/usr.bin/xlint/xlint/lint.1 cvs rdiff -u -r1.52 -r1.53 src/usr.bin/xlint/xlint/xlint.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.