Module Name:    src
Committed By:   rillig
Date:           Fri Apr  2 13:16:38 UTC 2021

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

Log Message:
tests/lint: add test for enum type mismatch


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/xlint/lint1/msg_130.c

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.12 src/tests/usr.bin/xlint/lint1/msg_130.c:1.13
--- src/tests/usr.bin/xlint/lint1/msg_130.c:1.12	Sun Mar 21 15:24:56 2021
+++ src/tests/usr.bin/xlint/lint1/msg_130.c	Fri Apr  2 13:16:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_130.c,v 1.12 2021/03/21 15:24:56 rillig Exp $	*/
+/*	$NetBSD: msg_130.c,v 1.13 2021/04/02 13:16:38 rillig Exp $	*/
 # 3 "msg_130.c"
 
 // Test for message: enum type mismatch: '%s' '%s' '%s' [130]
@@ -127,3 +127,44 @@ state_machine(const char *str)
 	if (state == sizeof_int)	/* expect: 130 */
 		return;
 }
+
+/*
+ * For check_case_label_enum, a warning only makes sense if the type of the
+ * enum can actually be specified somehow, either explicitly by using a tag
+ * name or a typedef name, or implicitly by using a variable in a switch
+ * expression.
+ */
+
+typedef enum {
+	has_typedef = 1001
+} typedef_name;
+
+enum tag_name {
+	has_tag = 1002
+};
+
+enum {
+	has_variable = 1003
+} variable;
+
+enum {
+	inaccessible = 1004
+};
+
+/*
+ * This check is already done by Clang, so it may not be necessary to add it
+ * to lint as well.  Except if there are some cases that Clang didn't
+ * implement.
+ */
+void
+test_check_case_label_enum(enum color color)
+{
+	switch (color)
+	{
+	case has_typedef:
+	case has_tag:
+	case has_variable:
+	case inaccessible:
+		return;
+	}
+}

Reply via email to