Module Name: src Committed By: rillig Date: Sun Jan 31 11:59:57 UTC 2021
Modified Files: src/tests/usr.bin/xlint/lint1: msg_160.c msg_160.exp Log Message: lint: add more test cases for strange '==' warning 160 To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_160.c cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_160.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/msg_160.c diff -u src/tests/usr.bin/xlint/lint1/msg_160.c:1.3 src/tests/usr.bin/xlint/lint1/msg_160.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_160.c:1.3 Sun Jan 31 11:12:07 2021 +++ src/tests/usr.bin/xlint/lint1/msg_160.c Sun Jan 31 11:59:56 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg_160.c,v 1.3 2021/01/31 11:12:07 rillig Exp $ */ +/* $NetBSD: msg_160.c,v 1.4 2021/01/31 11:59:56 rillig Exp $ */ # 3 "msg_160.c" // Test for message: operator '==' found where '=' was expected [160] @@ -9,5 +9,31 @@ _Bool both_equal_or_unequal(int a, int b, int c, int d) { /* XXX: Why shouldn't this be legitimate? */ - return (a == b) == (c == d); /* expect: 160, 160 */ + return (a == b) == (c == d); /* expect: 160, 160 */ +} + +void +eval(_Bool); + +void +unparenthesized(int a, int b, int c, _Bool z) +{ + /* + * This one might be legitimate since the second '==' has _Bool + * on both sides. Parenthesizing its left-hand operand doesn't + * hurt though. + */ + eval(a == b == z); /* expect: 160 */ + + eval((a == b) == z); /*FIXME*//* expect: 160 */ + + /* + * This one is definitely wrong. C, unlike Python, does not chain + * comparison operators in the way mathematicians are used to. + */ + eval(a == b == c); /* expect: 160 */ + + /* Parenthesizing one of the operands makes it obvious enough. */ + eval((a == b) == c); /*FIXME*//* expect: 160 */ + eval(a == (b == c)); /*FIXME*//* expect: 160 */ } Index: src/tests/usr.bin/xlint/lint1/msg_160.exp diff -u src/tests/usr.bin/xlint/lint1/msg_160.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_160.exp:1.3 --- src/tests/usr.bin/xlint/lint1/msg_160.exp:1.2 Sat Jan 9 15:32:06 2021 +++ src/tests/usr.bin/xlint/lint1/msg_160.exp Sun Jan 31 11:59:56 2021 @@ -1,2 +1,7 @@ msg_160.c(12): warning: operator '==' found where '=' was expected [160] msg_160.c(12): warning: operator '==' found where '=' was expected [160] +msg_160.c(26): warning: operator '==' found where '=' was expected [160] +msg_160.c(28): warning: operator '==' found where '=' was expected [160] +msg_160.c(34): warning: operator '==' found where '=' was expected [160] +msg_160.c(37): warning: operator '==' found where '=' was expected [160] +msg_160.c(38): warning: operator '==' found where '=' was expected [160]