Module Name:    src
Committed By:   rillig
Date:           Sat Feb 27 14:54:56 UTC 2021

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

Log Message:
tests/lint: add test for 'dubious operation on enum' [241]


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_241.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/msg_241.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_241.c
diff -u src/tests/usr.bin/xlint/lint1/msg_241.c:1.2 src/tests/usr.bin/xlint/lint1/msg_241.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_241.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_241.c	Sat Feb 27 14:54:55 2021
@@ -1,7 +1,73 @@
-/*	$NetBSD: msg_241.c,v 1.2 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: msg_241.c,v 1.3 2021/02/27 14:54:55 rillig Exp $	*/
 # 3 "msg_241.c"
 
 // Test for message: dubious operation on enum, op %s [241]
+//
+// As of February 2021, the option -e is not enabled by default in
+// share/mk/sys.mk, therefore this message is neither well-known nor
+// well-tested.
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* lint1-extra-flags: -e */
+
+/*
+ * Enums are a possible implementation of bit-sets.
+ */
+enum color {
+	RED	= 1 << 0,
+	GREEN	= 1 << 1,
+	BLUE	= 1 << 2
+};
+
+extern void sink(int);
+
+void
+example(void)
+{
+	enum color c = RED;
+
+	sink(!c);			/* expect: 241 */
+	sink(~c);			/* expect: 241, 278 */
+	++c;				/* expect: 241 */
+	--c;				/* expect: 241 */
+	c++;				/* expect: 241 */
+	c--;				/* expect: 241 */
+	sink(+c);			/* expect: 241, 278 */
+	sink(-c);			/* expect: 241, 278 */
+	sink(c * c);			/* expect: 241, 278 */
+	sink(c / c);			/* expect: 241, 278 */
+	sink(c % c);			/* expect: 241, 278 */
+	sink(c + c);			/* expect: 241, 278 */
+	sink(c - c);			/* expect: 241, 278 */
+	sink(c << c);			/* expect: 241, 278 */
+	sink(c >> c);			/* expect: 241, 278 */
+
+	sink(c < c);
+	sink(c <= c);
+	sink(c > c);
+	sink(c >= c);
+	sink(c == c);
+	sink(c != c);
+
+	sink(c & c);			/* expect: 241, 278 */
+	sink(c ^ c);			/* expect: 241, 278 */
+	sink(c | c);			/* expect: 241, 278 */
+
+	sink(c && c);			/* expect: 241 */
+	sink(c || c);			/* expect: 241 */
+	sink(c ? c : BLUE);		/* expect: 278 */
+
+	c = GREEN;
+	c *= c;				/* expect: 241 */
+	c /= c;				/* expect: 241 */
+	c %= c;				/* expect: 241 */
+	c += c;				/* expect: 241 */
+	c -= c;				/* expect: 241 */
+	c <<= c;			/* expect: 241 */
+	c >>= c;			/* expect: 241 */
+	c &= c;				/* expect: 241 */
+	c ^= c;				/* expect: 241 */
+	c |= c;				/* expect: 241 */
+
+	/* The cast to unsigned is required by GCC at WARNS=6. */
+	c &= ~(unsigned)GREEN;		/* expect: 241 */
+}

Index: src/tests/usr.bin/xlint/lint1/msg_241.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_241.exp:1.1 src/tests/usr.bin/xlint/lint1/msg_241.exp:1.2
--- src/tests/usr.bin/xlint/lint1/msg_241.exp:1.1	Sat Jan  2 10:22:44 2021
+++ src/tests/usr.bin/xlint/lint1/msg_241.exp	Sat Feb 27 14:54:55 2021
@@ -1 +1,45 @@
-msg_241.c(6): syntax error ':' [249]
+msg_241.c(28): warning: dubious operation on enum, op ! [241]
+msg_241.c(29): warning: dubious operation on enum, op ~ [241]
+msg_241.c(29): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(30): warning: dubious operation on enum, op ++x [241]
+msg_241.c(31): warning: dubious operation on enum, op --x [241]
+msg_241.c(32): warning: dubious operation on enum, op x++ [241]
+msg_241.c(33): warning: dubious operation on enum, op x-- [241]
+msg_241.c(34): warning: dubious operation on enum, op + [241]
+msg_241.c(34): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(35): warning: dubious operation on enum, op - [241]
+msg_241.c(35): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(36): warning: dubious operation on enum, op * [241]
+msg_241.c(36): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(37): warning: dubious operation on enum, op / [241]
+msg_241.c(37): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(38): warning: dubious operation on enum, op % [241]
+msg_241.c(38): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(39): warning: dubious operation on enum, op + [241]
+msg_241.c(39): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(40): warning: dubious operation on enum, op - [241]
+msg_241.c(40): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(41): warning: dubious operation on enum, op << [241]
+msg_241.c(41): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(42): warning: dubious operation on enum, op >> [241]
+msg_241.c(42): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(51): warning: dubious operation on enum, op & [241]
+msg_241.c(51): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(52): warning: dubious operation on enum, op ^ [241]
+msg_241.c(52): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(53): warning: dubious operation on enum, op | [241]
+msg_241.c(53): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(55): warning: dubious operation on enum, op && [241]
+msg_241.c(56): warning: dubious operation on enum, op || [241]
+msg_241.c(57): warning: combination of 'int' and 'enum color', arg #1 [278]
+msg_241.c(60): warning: dubious operation on enum, op *= [241]
+msg_241.c(61): warning: dubious operation on enum, op /= [241]
+msg_241.c(62): warning: dubious operation on enum, op %= [241]
+msg_241.c(63): warning: dubious operation on enum, op += [241]
+msg_241.c(64): warning: dubious operation on enum, op -= [241]
+msg_241.c(65): warning: dubious operation on enum, op <<= [241]
+msg_241.c(66): warning: dubious operation on enum, op >>= [241]
+msg_241.c(67): warning: dubious operation on enum, op &= [241]
+msg_241.c(68): warning: dubious operation on enum, op ^= [241]
+msg_241.c(69): warning: dubious operation on enum, op |= [241]
+msg_241.c(72): warning: dubious operation on enum, op &= [241]

Reply via email to