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: add test for 'assignme...



details:   https://anonhg.NetBSD.org/src/rev/fefddc76ce33
branches:  trunk
changeset: 368361:fefddc76ce33
user:      rillig <rillig%NetBSD.org@localhost>
date:      Wed Jul 06 21:13:13 2022 +0000

description:
tests/lint: add test for 'assignment in conditional context'

diffstat:

 tests/usr.bin/xlint/lint1/msg_159.c |  41 +++++++++++++++++++++++++++++++++---
 1 files changed, 37 insertions(+), 4 deletions(-)

diffs (49 lines):

diff -r 700ebaf3f410 -r fefddc76ce33 tests/usr.bin/xlint/lint1/msg_159.c
--- a/tests/usr.bin/xlint/lint1/msg_159.c       Wed Jul 06 17:35:20 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_159.c       Wed Jul 06 21:13:13 2022 +0000
@@ -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";
+}



Home | Main Index | Thread Index | Old Index