Module Name:    src
Committed By:   rillig
Date:           Thu May 11 08:01:36 UTC 2023

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

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_333.c
cvs rdiff -u -r1.153 -r1.154 src/usr.bin/xlint/lint1/func.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_333.c
diff -u src/tests/usr.bin/xlint/lint1/msg_333.c:1.5 src/tests/usr.bin/xlint/lint1/msg_333.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_333.c:1.5	Fri Jun 17 18:54:53 2022
+++ src/tests/usr.bin/xlint/lint1/msg_333.c	Thu May 11 08:01:36 2023
@@ -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";

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.153 src/usr.bin/xlint/lint1/func.c:1.154
--- src/usr.bin/xlint/lint1/func.c:1.153	Sat Apr 15 11:34:45 2023
+++ src/usr.bin/xlint/lint1/func.c	Thu May 11 08:01:36 2023
@@ -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;

Reply via email to