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: demonstrate non-enum w...
details: https://anonhg.NetBSD.org/src/rev/57e312d40e73
branches: trunk
changeset: 1026570:57e312d40e73
user: rillig <rillig%NetBSD.org@localhost>
date: Mon Nov 29 23:58:06 2021 +0000
description:
tests/lint: demonstrate non-enum warning for enum type mismatch
Seen in usr.bin/make/job.c:2122.
diffstat:
tests/usr.bin/xlint/lint1/msg_242.c | 25 ++++++++++++++++++++++++-
tests/usr.bin/xlint/lint1/msg_242.exp | 2 ++
2 files changed, 26 insertions(+), 1 deletions(-)
diffs (45 lines):
diff -r d06215c39e89 -r 57e312d40e73 tests/usr.bin/xlint/lint1/msg_242.c
--- a/tests/usr.bin/xlint/lint1/msg_242.c Mon Nov 29 20:03:15 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_242.c Mon Nov 29 23:58:06 2021 +0000
@@ -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 @@
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;
+}
diff -r d06215c39e89 -r 57e312d40e73 tests/usr.bin/xlint/lint1/msg_242.exp
--- a/tests/usr.bin/xlint/lint1/msg_242.exp Mon Nov 29 20:03:15 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_242.exp Mon Nov 29 23:58:06 2021 +0000
@@ -2,3 +2,5 @@
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]
Home |
Main Index |
Thread Index |
Old Index