Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: demonstrate missing er...



details:   https://anonhg.NetBSD.org/src/rev/abbb40459f94
branches:  trunk
changeset: 1026250:abbb40459f94
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Nov 14 11:23:52 2021 +0000

description:
tests/lint: demonstrate missing errors for strict bool mode

Seen in bin/echo/echo.c.

diffstat:

 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c   |  62 ++++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp |   5 ++
 2 files changed, 66 insertions(+), 1 deletions(-)

diffs (85 lines):

diff -r edea8eb1e18c -r abbb40459f94 tests/usr.bin/xlint/lint1/d_c99_bool_strict.c
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sun Nov 14 11:16:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.c     Sun Nov 14 11:23:52 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_bool_strict.c,v 1.30 2021/07/04 07:09:39 rillig Exp $    */
+/*     $NetBSD: d_c99_bool_strict.c,v 1.31 2021/11/14 11:23:52 rillig Exp $    */
 # 3 "d_c99_bool_strict.c"
 
 /*
@@ -776,3 +776,63 @@
            { 1 },              /* expect: 107 */
        };
 }
+
+# 1 "stdio.h" 1 3 4
+typedef struct stdio_file {
+       int fd;
+} FILE;
+int ferror(FILE *);
+FILE stdio_files[3];
+FILE *stdio_stdout;
+# 788 "d_c99_bool_strict.c" 2
+# 1 "string.h" 1 3 4
+int strcmp(const char *, const char *);
+# 791 "d_c99_bool_strict.c" 2
+
+void
+controlling_expression(FILE *f, const char *a, const char *b)
+{
+       /* expect+1: error: controlling expression must be bool, not 'int' [333] */
+       if (ferror(f))
+               return;
+       /* expect+1: error: controlling expression must be bool, not 'int' [333] */
+       if (strcmp(a, b))
+               return;
+       /* expect+1: error: operand of '!' must be bool, not 'int' [330] */
+       if (!ferror(f))
+               return;
+       /* expect+1: error: operand of '!' must be bool, not 'int' [330] */
+       if (!strcmp(a, b))
+               return;
+
+       /*
+        * No warning below since the expression 'stdio_stdin' comes from a
+        * system header (typically via a macro), and this property is passed
+        * up to the expression 'ferror(stdio_stdin)'.
+        *
+        * That is wrong though since the above rule would allow a plain
+        * 'strcmp' without a following '== 0', as long as one of its
+        * arguments comes from a system header.
+        *
+        * Seen in bin/echo/echo.c, function main, call to ferror.
+        */
+       /* TODO: Warn about type mismatch [333]. */
+       if (ferror(
+# 822 "d_c99_bool_strict.c" 3 4
+           &stdio_files[1]
+# 824 "d_c99_bool_strict.c"
+           ))
+               return;
+
+       /*
+        * TODO: Why is there a difference between array access and a plain
+        * variable? Either both should get a warning or none of them.
+        */
+       /* expect+5: error: controlling expression must be bool, not 'int' [333] */
+       if (ferror(
+# 834 "d_c99_bool_strict.c" 3 4
+           stdio_stdout
+# 836 "d_c99_bool_strict.c"
+           ))
+               return;
+}
diff -r edea8eb1e18c -r abbb40459f94 tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp
--- a/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sun Nov 14 11:16:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_bool_strict.exp   Sun Nov 14 11:23:52 2021 +0000
@@ -167,3 +167,8 @@
 d_c99_bool_strict.c(764): warning: constant in conditional context [161]
 d_c99_bool_strict.c(775): error: operands of 'init' have incompatible types (_Bool != int) [107]
 d_c99_bool_strict.c(776): error: operands of 'init' have incompatible types (_Bool != int) [107]
+d_c99_bool_strict.c(796): error: controlling expression must be bool, not 'int' [333]
+d_c99_bool_strict.c(799): error: controlling expression must be bool, not 'int' [333]
+d_c99_bool_strict.c(802): error: operand of '!' must be bool, not 'int' [330]
+d_c99_bool_strict.c(805): error: operand of '!' must be bool, not 'int' [330]
+d_c99_bool_strict.c(836): error: controlling expression must be bool, not 'int' [333]



Home | Main Index | Thread Index | Old Index