Module Name:    src
Committed By:   rillig
Date:           Sun Jan 24 09:18:42 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_bool_strict_syshdr.c
            d_c99_bool_strict_syshdr.exp

Log Message:
lint: improve introduction of test d_c99_bool_strict_syshdr


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 \
    src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c \
    src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp

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_syshdr.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.7 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.8
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.7	Sun Jan 24 07:58:48 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c	Sun Jan 24 09:18:42 2021
@@ -1,11 +1,22 @@
-/*	$NetBSD: d_c99_bool_strict_syshdr.c,v 1.7 2021/01/24 07:58:48 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict_syshdr.c,v 1.8 2021/01/24 09:18:42 rillig Exp $	*/
 # 3 "d_c99_bool_strict_syshdr.c"
 
 /*
- * Macros from system headers may use int expressions where bool expressions
- * are expected.  These headers are not allowed to include <stdbool.h>
- * themselves, and even if they could, lint must accept other scalar types
- * as well, since system headers are not changed lightheartedly.
+ * In strict bool mode, lint treats bool as incompatible with any other scalar
+ * types.  This mode helps in migrating code from pre-C99 to C99.
+ *
+ * System headers, on the other hand, cannot be migrated if they need to stay
+ * compatible with pre-C99 code.  Therefore, the checks for system headers are
+ * loosened.  In contexts where a scalar expression is compared to 0, macros
+ * and functions from system headers may use int expressions as well.
+ *
+ * These headers are not allowed to include <stdbool.h>[references needed].
+ * Doing so would inject lint's own <stdbool.h>, which defines the macros
+ * false and true to other identifiers instead of the plain 0 and 1, thereby
+ * allowing to see whether the code really uses true and false as identifiers.
+ *
+ * Since the system headers cannot include <stdbool.h>, they need to use the
+ * traditional bool constants 0 and 1.
  */
 
 /* lint1-extra-flags: -T */
@@ -31,12 +42,12 @@ strict_bool_system_header_statement_macr
 		println("nothing");
 	} while (/*CONSTCOND*/0);	/* expect: 333 */
 
-# 35 "d_c99_bool_strict_syshdr.c" 3 4
+# 46 "d_c99_bool_strict_syshdr.c" 3 4
 	do {
 		println("nothing");
 	} while (/*CONSTCOND*/0);	/* ok */
 
-# 40 "d_c99_bool_strict_syshdr.c"
+# 51 "d_c99_bool_strict_syshdr.c"
 	do {
 		println("nothing");
 	} while (/*CONSTCOND*/0);	/* expect: 333 */
@@ -70,28 +81,28 @@ strict_bool_system_header_ctype(int c)
 	 * All other combinations of type are safe from truncation.
 	 */
 	_Bool system_int_assigned_to_bool =
-# 74 "d_c99_bool_strict_syshdr.c" 3 4
+# 85 "d_c99_bool_strict_syshdr.c" 3 4
 	    (int)((ctype_table + 1)[c] & 0x0040)	/* INT */
-# 76 "d_c99_bool_strict_syshdr.c"
+# 87 "d_c99_bool_strict_syshdr.c"
 	;			/* expect: 107 */
 
 	int system_bool_assigned_to_int =
-# 80 "d_c99_bool_strict_syshdr.c" 3 4
+# 91 "d_c99_bool_strict_syshdr.c" 3 4
 	    (int)((ctype_table + 1)[c] & 0x0040) != 0	/* BOOL */
-# 82 "d_c99_bool_strict_syshdr.c"
+# 93 "d_c99_bool_strict_syshdr.c"
 	;
 
 	if (
-# 86 "d_c99_bool_strict_syshdr.c" 3 4
+# 97 "d_c99_bool_strict_syshdr.c" 3 4
 	    (int)((ctype_table + 1)[c] & 0x0040)	/* INT */
-# 88 "d_c99_bool_strict_syshdr.c"
+# 99 "d_c99_bool_strict_syshdr.c"
 	)
 		println("system macro returning INT");
 
 	if (
-# 93 "d_c99_bool_strict_syshdr.c" 3 4
+# 104 "d_c99_bool_strict_syshdr.c" 3 4
 	    ((ctype_table + 1)[c] & 0x0040) != 0	/* BOOL */
-# 95 "d_c99_bool_strict_syshdr.c"
+# 106 "d_c99_bool_strict_syshdr.c"
 	)
 		println("system macro returning BOOL");
 }
@@ -100,9 +111,9 @@ static inline _Bool
 ch_isspace_sys_int(char c)
 {
 	return
-# 104 "d_c99_bool_strict_syshdr.c" 3 4
+# 115 "d_c99_bool_strict_syshdr.c" 3 4
 	    ((ctype_table + 1)[c] & 0x0040)
-# 106 "d_c99_bool_strict_syshdr.c"
+# 117 "d_c99_bool_strict_syshdr.c"
 	    != 0;
 }
 
@@ -115,9 +126,9 @@ static inline _Bool
 ch_isspace_sys_bool(char c)
 {
 	return
-# 119 "d_c99_bool_strict_syshdr.c" 3 4
+# 130 "d_c99_bool_strict_syshdr.c" 3 4
 	    ((ctype_table + 1)[(unsigned char)c] & 0x0040) != 0
-# 121 "d_c99_bool_strict_syshdr.c"
+# 132 "d_c99_bool_strict_syshdr.c"
 	    != 0;
 }
 
@@ -142,7 +153,7 @@ ch_isspace_sys_bool(char c)
 extern int finite(double);
 # 1 "string.h" 3 4
 extern int strcmp(const char *, const char *);
-# 146 "d_c99_bool_strict_syshdr.c"
+# 157 "d_c99_bool_strict_syshdr.c"
 
 /*ARGSUSED*/
 _Bool
Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.7 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.8
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp:1.7	Sun Jan 24 07:58:48 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.exp	Sun Jan 24 09:18:42 2021
@@ -1,6 +1,6 @@
-d_c99_bool_strict_syshdr.c(32): controlling expression must be bool, not 'int' [333]
-d_c99_bool_strict_syshdr.c(42): controlling expression must be bool, not 'int' [333]
-d_c99_bool_strict_syshdr.c(76): operands of '=' have incompatible types (_Bool != int) [107]
-d_c99_bool_strict_syshdr.c(151): return value type mismatch (_Bool) and (int) [211]
-d_c99_bool_strict_syshdr.c(164): operand of '!' must be bool, not 'int' [330]
-d_c99_bool_strict_syshdr.c(164): warning: function str_equal_bad expects to return value [214]
+d_c99_bool_strict_syshdr.c(43): controlling expression must be bool, not 'int' [333]
+d_c99_bool_strict_syshdr.c(53): controlling expression must be bool, not 'int' [333]
+d_c99_bool_strict_syshdr.c(87): operands of '=' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict_syshdr.c(162): return value type mismatch (_Bool) and (int) [211]
+d_c99_bool_strict_syshdr.c(175): operand of '!' must be bool, not 'int' [330]
+d_c99_bool_strict_syshdr.c(175): warning: function str_equal_bad expects to return value [214]

Reply via email to