lint: explain failing test case in strict bool mode

This commit is contained in:
rillig 2021-01-17 13:15:03 +00:00
parent 72a430e500
commit 4567bafeac
2 changed files with 23 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: d_c99_bool_strict.c,v 1.13 2021/01/17 11:32:06 rillig Exp $ */
/* $NetBSD: d_c99_bool_strict.c,v 1.14 2021/01/17 13:15:03 rillig Exp $ */
# 3 "d_c99_bool_strict.c"
/*
@ -716,6 +716,27 @@ strict_bool_operator_eq_bool_int(void)
(void)(strict_bool_conversion_return_false() == 0); /* expect: 107 */
}
/*
* When building the NE node, the following steps happen:
*
* ln is promoted from BOOL:1 to INT:1 since it is a bit field and C90 says
* that bit fields must always be promoted to int.
*
* rn is promoted from BOOL. promote() does not handle BOOL explicitly,
* therefore it is kept as-is. That may or may not have been an oversight
* in the initial implementation of supporting BOOL.
*
* After that, the two nodes are balanced. At this point, their types are
* INT:1 and BOOL. INT is considered the larger of the two types, even
* though it is a bit field in this case. Therefore BOOL is converted to
* INT now, and since it is a constant, the converted node loses all
* information about its previous type.
*
* During these conversions and promotions, the code asks whether BOOL
* is an arithmetic type. If that isn't the case, no conversion or
* promotion takes place. Since strict bool mode explicitly treats BOOL
* as non-arithmetic, changing is_arithmetic sounds like the way to go.
*/
void
strict_bool_assign_bit_field_then_compare(void)
{

View File

@ -142,4 +142,4 @@ d_c99_bool_strict.c(670): operands of '=' have incompatible types (_Bool != int)
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(729): operands of '!=' have incompatible types (_Bool != int) [107]
d_c99_bool_strict.c(750): operands of '!=' have incompatible types (_Bool != int) [107]