Module Name:    src
Committed By:   rillig
Date:           Sun Feb 21 10:28:33 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_struct_init_nested.exp msg_210.exp
        src/usr.bin/xlint/common: tyname.c
        src/usr.bin/xlint/lint1: err.c tree.c

Log Message:
lint: add type information to message about enum mismatch


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
    src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_210.exp
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/xlint/common/tyname.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.213 -r1.214 src/usr.bin/xlint/lint1/tree.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/d_struct_init_nested.exp
diff -u src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp:1.3 src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp:1.4
--- src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp:1.3	Sun Jan 31 14:39:31 2021
+++ src/tests/usr.bin/xlint/lint1/d_struct_init_nested.exp	Sun Feb 21 10:28:33 2021
@@ -1,4 +1,4 @@
 d_struct_init_nested.c(35): initialisation type mismatch (enum I1) and (struct Inner1) [185]
 d_struct_init_nested.c(37): too many struct/union initializers [172]
 d_struct_init_nested.c(62): initialisation type mismatch (enum I1) and (struct Inner2) [185]
-d_struct_init_nested.c(64): warning: enum type mismatch in initialisation [210]
+d_struct_init_nested.c(64): warning: enum type mismatch between 'enum I2' and 'enum O3' in initialisation [210]

Index: src/tests/usr.bin/xlint/lint1/msg_210.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_210.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_210.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_210.exp:1.2	Sun Feb 21 10:12:29 2021
+++ src/tests/usr.bin/xlint/lint1/msg_210.exp	Sun Feb 21 10:28:33 2021
@@ -1,2 +1,2 @@
-msg_210.c(23): warning: enum type mismatch in initialisation [210]
-msg_210.c(25): warning: enum type mismatch in initialisation [210]
+msg_210.c(23): warning: enum type mismatch between 'enum A' and 'enum B' in initialisation [210]
+msg_210.c(25): warning: enum type mismatch between 'C' and 'D' in initialisation [210]

Index: src/usr.bin/xlint/common/tyname.c
diff -u src/usr.bin/xlint/common/tyname.c:1.29 src/usr.bin/xlint/common/tyname.c:1.30
--- src/usr.bin/xlint/common/tyname.c:1.29	Fri Feb 19 22:27:49 2021
+++ src/usr.bin/xlint/common/tyname.c	Sun Feb 21 10:28:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tyname.c,v 1.29 2021/02/19 22:27:49 rillig Exp $	*/
+/*	$NetBSD: tyname.c,v 1.30 2021/02/21 10:28:32 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tyname.c,v 1.29 2021/02/19 22:27:49 rillig Exp $");
+__RCSID("$NetBSD: tyname.c,v 1.30 2021/02/21 10:28:32 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -337,10 +337,17 @@ type_name(const type_t *tp)
 		buf_add(&buf, type_name(tp->t_subt));
 		break;
 	case ENUM:
-		buf_add(&buf, " ");
 #ifdef t_enum
-		buf_add(&buf, tp->t_enum->en_tag->s_name);
+		if (tp->t_enum->en_tag->s_name == unnamed &&
+		    tp->t_enum->en_first_typedef != NULL) {
+			buf.len -= strlen(tspec_name(t));
+			buf_add(&buf, tp->t_enum->en_first_typedef->s_name);
+		} else {
+			buf_add(&buf, " ");
+			buf_add(&buf, tp->t_enum->en_tag->s_name);
+		}
 #else
+		buf_add(&buf, " ");
 		buf_add(&buf,
 		    tp->t_isuniqpos ? "*anonymous*" : tp->t_tag->h_name);
 #endif

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.79 src/usr.bin/xlint/lint1/err.c:1.80
--- src/usr.bin/xlint/lint1/err.c:1.79	Fri Feb 19 12:28:56 2021
+++ src/usr.bin/xlint/lint1/err.c	Sun Feb 21 10:28:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.79 2021/02/19 12:28:56 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.80 2021/02/21 10:28:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.79 2021/02/19 12:28:56 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.80 2021/02/21 10:28:33 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -269,7 +269,7 @@ const	char *msgs[] = {
 	"loop not entered at top",				      /* 207 */
 	"break outside loop or switch",				      /* 208 */
 	"continue outside loop",				      /* 209 */
-	"enum type mismatch in initialisation",			      /* 210 */
+	"enum type mismatch between '%s' and '%s' in initialisation", /* 210 */
 	"return value type mismatch (%s) and (%s)",		      /* 211 */
 	"cannot return incomplete type",			      /* 212 */
 	"void function %s cannot return value",			      /* 213 */

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.213 src/usr.bin/xlint/lint1/tree.c:1.214
--- src/usr.bin/xlint/lint1/tree.c:1.213	Sun Feb 21 07:21:57 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Feb 21 10:28:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.213 2021/02/21 07:21:57 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.214 2021/02/21 10:28:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.213 2021/02/21 07:21:57 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.214 2021/02/21 10:28:33 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -1717,8 +1717,9 @@ check_enum_type_mismatch(op_t op, int ar
 	if (ln->tn_type->t_enum != rn->tn_type->t_enum) {
 		switch (op) {
 		case INIT:
-			/* enum type mismatch in initialisation */
-			warning(210);
+			/* enum type mismatch between '%s' and '%s' in ... */
+			warning(210,
+			    type_name(ln->tn_type), type_name(rn->tn_type));
 			break;
 		case FARG:
 			/* enum type mismatch, arg #%d (%s != %s) */

Reply via email to