Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: fix type name in diagnostic for en...



details:   https://anonhg.NetBSD.org/src/rev/eac1a76c387d
branches:  trunk
changeset: 374749:eac1a76c387d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu May 11 08:01:36 2023 +0000

description:
lint: fix type name in diagnostic for enum as controlling expression

Previously, the type was reported as 'int' instead of 'enum'.

Continue to only report the type simple for pointer types, as the exact
pointer type is irrelevant to this message.

diffstat:

 tests/usr.bin/xlint/lint1/msg_333.c |  18 +++++++++++++++++-
 usr.bin/xlint/lint1/func.c          |   7 ++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

diffs (67 lines):

diff -r 882aab74f45d -r eac1a76c387d tests/usr.bin/xlint/lint1/msg_333.c
--- a/tests/usr.bin/xlint/lint1/msg_333.c       Thu May 11 07:47:14 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_333.c       Thu May 11 08:01:36 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_333.c,v 1.5 2022/06/17 18:54:53 rillig Exp $       */
+/*     $NetBSD: msg_333.c,v 1.6 2023/05/11 08:01:36 rillig Exp $       */
 # 3 "msg_333.c"
 
 // Test for message: controlling expression must be bool, not '%s' [333]
@@ -9,6 +9,14 @@
 
 typedef _Bool bool;
 
+static enum tagged_color {
+       tagged_red,
+} e1;
+typedef enum {
+       typedef_red,
+} typedef_color;
+static typedef_color e2;
+
 const char *
 example(bool b, int i, const char *p)
 {
@@ -20,6 +28,14 @@ example(bool b, int i, const char *p)
        if (i)
                return "int";
 
+       /* expect+1: error: controlling expression must be bool, not 'enum tagged_color' [333] */
+       if (e1)
+               return "tagged enum";
+
+       /* expect+1: error: controlling expression must be bool, not 'enum typedef typedef_color' [333] */
+       if (e2)
+               return "typedef enum";
+
        /* expect+1: error: controlling expression must be bool, not 'pointer' [333] */
        if (p)
                return "pointer";
diff -r 882aab74f45d -r eac1a76c387d usr.bin/xlint/lint1/func.c
--- a/usr.bin/xlint/lint1/func.c        Thu May 11 07:47:14 2023 +0000
+++ b/usr.bin/xlint/lint1/func.c        Thu May 11 08:01:36 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: func.c,v 1.153 2023/04/15 11:34:45 rillig Exp $        */
+/*     $NetBSD: func.c,v 1.154 2023/05/11 08:01:36 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.153 2023/04/15 11:34:45 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.154 2023/05/11 08:01:36 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -623,7 +623,8 @@ check_controlling_expression(tnode_t *tn
 
        if (tn != NULL && Tflag && !is_typeok_bool_compares_with_zero(tn)) {
                /* controlling expression must be bool, not '%s' */
-               error(333, tspec_name(tn->tn_type->t_tspec));
+               error(333, tn->tn_type->t_is_enum ? type_name(tn->tn_type)
+                   : tspec_name(tn->tn_type->t_tspec));
        }
 
        return tn;



Home | Main Index | Thread Index | Old Index