Module Name:    src
Committed By:   rillig
Date:           Mon Nov 29 23:58:06 UTC 2021

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

Log Message:
tests/lint: demonstrate non-enum warning for enum type mismatch

Seen in usr.bin/make/job.c:2122.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_242.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_242.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_242.c
diff -u src/tests/usr.bin/xlint/lint1/msg_242.c:1.4 src/tests/usr.bin/xlint/lint1/msg_242.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_242.c:1.4	Sat Aug 14 12:46:24 2021
+++ src/tests/usr.bin/xlint/lint1/msg_242.c	Mon Nov 29 23:58:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_242.c,v 1.4 2021/08/14 12:46:24 rillig Exp $	*/
+/*	$NetBSD: msg_242.c,v 1.5 2021/11/29 23:58:06 rillig Exp $	*/
 # 3 "msg_242.c"
 
 // Test for message: combination of '%s' and '%s', op %s [242]
@@ -32,3 +32,26 @@ example(enum E e, int i)
 	sink_int(i2);
 	sink_int(i3);
 }
+
+
+/*
+ * In C, the only ways to create named compile-time integer constants are
+ * preprocessor macros or enum constants. All other expressions do not count
+ * as constant expressions, even if they are declared 'static const' or
+ * 'const'.
+ */
+unsigned
+unnamed_enum(void)
+{
+	enum {
+		compile_time_constant = 2
+	};
+
+	unsigned i = 3;
+
+	/* expect+3: warning: dubious operation on enum, op * [241] */
+	/* FIXME: Combining 'unsigned int' with 'unsigned int' is OK. */
+	/* expect+1: warning: combination of 'unsigned int' and 'unsigned int', op = [242] */
+	i = compile_time_constant * i;
+	return i;
+}

Index: src/tests/usr.bin/xlint/lint1/msg_242.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_242.exp:1.3 src/tests/usr.bin/xlint/lint1/msg_242.exp:1.4
--- src/tests/usr.bin/xlint/lint1/msg_242.exp:1.3	Sat Aug 14 12:46:24 2021
+++ src/tests/usr.bin/xlint/lint1/msg_242.exp	Mon Nov 29 23:58:06 2021
@@ -2,3 +2,5 @@ msg_242.c(20): warning: initialization o
 msg_242.c(22): warning: initialization of 'int' with 'enum E' [277]
 msg_242.c(26): warning: combination of 'enum E' and 'int', op = [242]
 msg_242.c(28): warning: combination of 'int' and 'enum E', op = [242]
+msg_242.c(55): warning: dubious operation on enum, op * [241]
+msg_242.c(55): warning: combination of 'unsigned int' and 'unsigned int', op = [242]

Reply via email to