tests/lint: add test for suppressing errors in strict bool mode

This commit is contained in:
rillig 2021-07-04 07:50:53 +00:00
parent 8d5c9f256b
commit 3020101578
4 changed files with 54 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1072 2021/07/03 19:31:22 rillig Exp $
# $NetBSD: mi,v 1.1073 2021/07/04 07:50:53 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -6107,6 +6107,8 @@
./usr/tests/usr.bin/xlint/lint1/Kyuafile tests-usr.bin-tests compattestfile,atf,kyua
./usr/tests/usr.bin/xlint/lint1/c11_generic_expression.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/c11_generic_expression.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/c99_bool_strict_suppressed.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/c99_bool_strict_suppressed.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/c99_init_array.c tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/c99_init_array.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/xlint/lint1/c99_init_designator.c tests-usr.bin-tests compattestfile,atf

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.74 2021/07/03 19:31:22 rillig Exp $
# $NetBSD: Makefile,v 1.75 2021/07/04 07:50:53 rillig Exp $
NOMAN= # defined
MAX_MESSAGE= 345 # see lint1/err.c
@ -12,6 +12,8 @@ TESTS_SH= t_integration
FILESDIR= ${TESTSDIR}
FILES+= c11_generic_expression.c
FILES+= c11_generic_expression.exp
FILES+= c99_bool_strict_suppressed.c
FILES+= c99_bool_strict_suppressed.exp
FILES+= c99_init_array.c
FILES+= c99_init_array.exp
FILES+= c99_init_designator.c

View File

@ -0,0 +1,43 @@
/* $NetBSD: c99_bool_strict_suppressed.c,v 1.1 2021/07/04 07:50:53 rillig Exp $ */
# 3 "c99_bool_strict_suppressed.c"
/*
* In strict bool mode, like everywhere else, individual errors can be
* suppressed. Suppressing a message affects lint's output as well as the
* exit status. Lint's control flow stays the same as before though.
*
* This can result in assertion failures later. One such assertion has been
* there since at least 1995, at the beginning of expr(), ensuring that the
* expression is either non-null or an error message has been _printed_.
* In 1995 it was not possible to suppress error messages, which means that
* the number of printed errors equaled the number of occurred errors.
*
* In err.c 1.12 from 2000-07-06, the option -X was added, allowing to
* suppress individual error messages. That commit did not mention any
* interaction with the assertion in expr().
*/
/* lint1-extra-flags: -T */
/* TODO: -X 107,330,331,332,333 */
/* ARGSUSED */
void
test(_Bool b, int i, const char *p)
{
/* expect+1: error: controlling expression must be bool, not 'int' [333] */
while (1)
break;
/* expect+1: error: operands of '=' have incompatible types (_Bool != int) [107] */
b = i;
/* expect+1: error: operand of '!' must be bool, not 'int' [330] */
b = !i;
/* expect+1: error: left operand of '&&' must be bool, not 'int' [331] */
b = i && b;
/* expect+1: error: right operand of '&&' must be bool, not 'int' [332] */
b = b && i;
}

View File

@ -0,0 +1,5 @@
c99_bool_strict_suppressed.c(29): error: controlling expression must be bool, not 'int' [333]
c99_bool_strict_suppressed.c(33): error: operands of '=' have incompatible types (_Bool != int) [107]
c99_bool_strict_suppressed.c(36): error: operand of '!' must be bool, not 'int' [330]
c99_bool_strict_suppressed.c(39): error: left operand of '&&' must be bool, not 'int' [331]
c99_bool_strict_suppressed.c(42): error: right operand of '&&' must be bool, not 'int' [332]