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: add test for enum type...



details:   https://anonhg.NetBSD.org/src/rev/e44be671f234
branches:  trunk
changeset: 954231:e44be671f234
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Apr 02 13:16:38 2021 +0000

description:
tests/lint: add test for enum type mismatch

diffstat:

 tests/usr.bin/xlint/lint1/msg_130.c |  43 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 42 insertions(+), 1 deletions(-)

diffs (54 lines):

diff -r a0dc16bbb697 -r e44be671f234 tests/usr.bin/xlint/lint1/msg_130.c
--- a/tests/usr.bin/xlint/lint1/msg_130.c       Fri Apr 02 12:16:50 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_130.c       Fri Apr 02 13:16:38 2021 +0000
@@ -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 @@
        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;
+       }
+}



Home | Main Index | Thread Index | Old Index