Module Name:    src
Committed By:   rillig
Date:           Sat Feb 27 13:43:36 UTC 2021

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

Log Message:
tests/lint: add more tests for enum mismatch


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_130.c \
    src/tests/usr.bin/xlint/lint1/msg_156.c \
    src/tests/usr.bin/xlint/lint1/msg_156.exp
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_130.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_130.c
diff -u src/tests/usr.bin/xlint/lint1/msg_130.c:1.3 src/tests/usr.bin/xlint/lint1/msg_130.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_130.c:1.3	Sun Jan 31 11:12:07 2021
+++ src/tests/usr.bin/xlint/lint1/msg_130.c	Sat Feb 27 13:43:36 2021
@@ -1,18 +1,39 @@
-/*	$NetBSD: msg_130.c,v 1.3 2021/01/31 11:12:07 rillig Exp $	*/
+/*	$NetBSD: msg_130.c,v 1.4 2021/02/27 13:43:36 rillig Exp $	*/
 # 3 "msg_130.c"
 
 // Test for message: enum type mismatch, op %s [130]
 
 enum color {
-	RED, GREEN, BLUE
+	RED	= 1 << 0,
+	GREEN	= 1 << 1,
+	BLUE	= 1 << 2
+};
+
+enum size {
+	SMALL,
+	MEDIUM,
+	LARGE
 };
 
 enum daytime {
 	NIGHT, MORNING, NOON, EVENING
 };
 
-int
-example(_Bool cond)
+void sink(_Bool);
+
+void
+example(_Bool cond, enum color c, enum size s)
 {
-	return cond ? GREEN : MORNING;	/* expect: 130 */
+	sink(cond ? GREEN : MORNING);	/* expect: 130 */
+
+	sink(c != s);			/* expect: 130 */
+	sink(c == s);			/* expect: 130 */
+	sink((c & MEDIUM) != 0);	/* might be useful to warn about */
+	sink((c | MEDIUM) != 0);	/* might be useful to warn about */
+
+	c |= MEDIUM;			/* might be useful to warn about */
+	c &= MEDIUM;			/* might be useful to warn about */
+
+	/* The cast to unsigned is required by GCC at WARNS=6. */
+	c &= ~(unsigned)MEDIUM;		/* might be useful to warn about */
 }
Index: src/tests/usr.bin/xlint/lint1/msg_156.c
diff -u src/tests/usr.bin/xlint/lint1/msg_156.c:1.3 src/tests/usr.bin/xlint/lint1/msg_156.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_156.c:1.3	Sun Jan 31 11:12:07 2021
+++ src/tests/usr.bin/xlint/lint1/msg_156.c	Sat Feb 27 13:43:36 2021
@@ -1,12 +1,12 @@
-/*	$NetBSD: msg_156.c,v 1.3 2021/01/31 11:12:07 rillig Exp $	*/
+/*	$NetBSD: msg_156.c,v 1.4 2021/02/27 13:43:36 rillig Exp $	*/
 # 3 "msg_156.c"
 
 // Test for message: enum type mismatch, arg #%d [156]
 
 enum color {
-	RED,
-	GREEN,
-	BLUE
+	RED	= 1 << 0,
+	GREEN	= 1 << 1,
+	BLUE	= 1 << 2
 };
 
 enum size {
@@ -15,11 +15,14 @@ enum size {
 	LARGE
 };
 
-void
-print_color(enum color);
+void print_color(enum color);
 
 void
-example(void)
+example(enum color c, enum size s)
 {
+	print_color(GREEN);
+	print_color(c);
+
 	print_color(MEDIUM);		/* expect: 156 */
+	print_color(s);			/* expect: 156 */
 }
Index: src/tests/usr.bin/xlint/lint1/msg_156.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_156.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_156.exp:1.4
--- src/tests/usr.bin/xlint/lint1/msg_156.exp:1.3	Thu Jan 14 07:42:31 2021
+++ src/tests/usr.bin/xlint/lint1/msg_156.exp	Sat Feb 27 13:43:36 2021
@@ -1 +1,2 @@
-msg_156.c(24): warning: enum type mismatch, arg #1 (enum color != enum size) [156]
+msg_156.c(26): warning: enum type mismatch, arg #1 (enum color != enum size) [156]
+msg_156.c(27): warning: enum type mismatch, arg #1 (enum color != enum size) [156]

Index: src/tests/usr.bin/xlint/lint1/msg_130.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_130.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_130.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_130.exp:1.2	Fri Jan  8 21:25:03 2021
+++ src/tests/usr.bin/xlint/lint1/msg_130.exp	Sat Feb 27 13:43:36 2021
@@ -1 +1,3 @@
-msg_130.c(17): warning: enum type mismatch, op : [130]
+msg_130.c(27): warning: enum type mismatch, op : [130]
+msg_130.c(29): warning: enum type mismatch, op != [130]
+msg_130.c(30): warning: enum type mismatch, op == [130]

Reply via email to