Module Name: src Committed By: rillig Date: Wed Jul 6 21:13:13 UTC 2022
Modified Files: src/tests/usr.bin/xlint/lint1: msg_159.c Log Message: tests/lint: add test for 'assignment in conditional context' To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_159.c 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_159.c diff -u src/tests/usr.bin/xlint/lint1/msg_159.c:1.3 src/tests/usr.bin/xlint/lint1/msg_159.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_159.c:1.3 Thu Jun 16 16:58:36 2022 +++ src/tests/usr.bin/xlint/lint1/msg_159.c Wed Jul 6 21:13:13 2022 @@ -1,8 +1,41 @@ -/* $NetBSD: msg_159.c,v 1.3 2022/06/16 16:58:36 rillig Exp $ */ +/* $NetBSD: msg_159.c,v 1.4 2022/07/06 21:13:13 rillig Exp $ */ # 3 "msg_159.c" // Test for message: assignment in conditional context [159] -/* expect+1: error: syntax error ':' [249] */ -TODO: "Add example code that triggers the above message." -TODO: "Add example code that almost triggers the above message." +/* lint1-extra-flags: -h */ + +const char * +example(int a, int b) +{ + + if (a == b) + return "comparison, not parenthesized"; + + if ((a == b)) + return "comparison, parenthesized"; + + if ( +# 20 "msg_159.c" 3 4 + (a == b) +# 22 "msg_159.c" + ) + return "comparison, parenthesized, from system header"; + + /* expect+1: warning: assignment in conditional context [159] */ + if (a = b) + return "assignment, not parenthesized"; + + /* + * XXX: GCC has the convention that an assignment that is + * parenthesized is intended as an assignment. + */ + /* expect+1: warning: assignment in conditional context [159] */ + if ((a = b)) + return "assignment, parenthesized"; + + if ((a = b) != 0) + return "explicit comparison after assignment"; + + return "other"; +}