Module Name:    src
Committed By:   rillig
Date:           Sun Jul  4 17:01:58 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_101.c msg_101.exp msg_103.c
            msg_103.exp msg_104.c msg_104.exp
        src/usr.bin/xlint/lint1: err.c tree.c

Log Message:
lint: align messages for invalid left operand of '.' or '->'


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_101.c \
    src/tests/usr.bin/xlint/lint1/msg_101.exp
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_103.c \
    src/tests/usr.bin/xlint/lint1/msg_103.exp \
    src/tests/usr.bin/xlint/lint1/msg_104.c \
    src/tests/usr.bin/xlint/lint1/msg_104.exp
cvs rdiff -u -r1.124 -r1.125 src/usr.bin/xlint/lint1/err.c
cvs rdiff -u -r1.309 -r1.310 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/msg_101.c
diff -u src/tests/usr.bin/xlint/lint1/msg_101.c:1.6 src/tests/usr.bin/xlint/lint1/msg_101.c:1.7
--- src/tests/usr.bin/xlint/lint1/msg_101.c:1.6	Wed Jun 30 14:11:08 2021
+++ src/tests/usr.bin/xlint/lint1/msg_101.c	Sun Jul  4 17:01:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_101.c,v 1.6 2021/06/30 14:11:08 rillig Exp $	*/
+/*	$NetBSD: msg_101.c,v 1.7 2021/07/04 17:01:58 rillig Exp $	*/
 # 3 "msg_101.c"
 
 // Test for message: type '%s' does not have member '%s' [101]
@@ -23,11 +23,9 @@ test(const struct point *ptr, const stru
 	sink(pt.z);
 
 	/* mixed up '.' and '->' */
-	/* TODO: mention actual type in the diagnostic */
-	/* expect+1: error: left operand of '.' must be struct/union object [103] */
+	/* expect+1: error: left operand of '.' must be struct or union, not 'pointer to const struct point' [103] */
 	sink(ptr.x);
-	/* TODO: put actual type in 'quotes' */
-	/* expect+1: error: left operand of '->' must be pointer to struct/union not struct point [104] */
+	/* expect+1: error: left operand of '->' must be pointer to struct or union, not 'struct point' [104] */
 	sink(pt->x);
 
 	/* accessing a nonexistent member via the wrong operator */
Index: src/tests/usr.bin/xlint/lint1/msg_101.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_101.exp:1.6 src/tests/usr.bin/xlint/lint1/msg_101.exp:1.7
--- src/tests/usr.bin/xlint/lint1/msg_101.exp:1.6	Wed Jun 30 14:11:08 2021
+++ src/tests/usr.bin/xlint/lint1/msg_101.exp	Sun Jul  4 17:01:58 2021
@@ -1,6 +1,6 @@
 msg_101.c(21): error: type 'pointer to const struct point' does not have member 'z' [101]
 msg_101.c(23): error: type 'const struct point' does not have member 'z' [101]
-msg_101.c(28): error: left operand of '.' must be struct/union object [103]
-msg_101.c(31): error: left operand of '->' must be pointer to struct/union not struct point [104]
-msg_101.c(35): error: type 'pointer to const struct point' does not have member 'z' [101]
-msg_101.c(38): error: type 'struct point' does not have member 'z' [101]
+msg_101.c(27): error: left operand of '.' must be struct or union, not 'pointer to const struct point' [103]
+msg_101.c(29): error: left operand of '->' must be pointer to struct or union, not 'struct point' [104]
+msg_101.c(33): error: type 'pointer to const struct point' does not have member 'z' [101]
+msg_101.c(36): error: type 'struct point' does not have member 'z' [101]

Index: src/tests/usr.bin/xlint/lint1/msg_103.c
diff -u src/tests/usr.bin/xlint/lint1/msg_103.c:1.2 src/tests/usr.bin/xlint/lint1/msg_103.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_103.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_103.c	Sun Jul  4 17:01:58 2021
@@ -1,7 +1,16 @@
-/*	$NetBSD: msg_103.c,v 1.2 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: msg_103.c,v 1.3 2021/07/04 17:01:58 rillig Exp $	*/
 # 3 "msg_103.c"
 
-// Test for message: left operand of '.' must be struct/union object [103]
+// Test for message: left operand of '.' must be struct or union, not '%s' [103]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+struct point {
+	int x, y;
+};
+
+void
+test(struct point pt, struct point *ptr)
+{
+	pt.x = 0;
+	/* expect+1: left operand of '.' must be struct or union, not 'pointer to struct point' [103] */
+	ptr.y = 0;
+}
Index: src/tests/usr.bin/xlint/lint1/msg_103.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_103.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_103.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_103.exp:1.2	Sun Mar 21 20:44:59 2021
+++ src/tests/usr.bin/xlint/lint1/msg_103.exp	Sun Jul  4 17:01:58 2021
@@ -1 +1 @@
-msg_103.c(6): error: syntax error ':' [249]
+msg_103.c(15): error: left operand of '.' must be struct or union, not 'pointer to struct point' [103]
Index: src/tests/usr.bin/xlint/lint1/msg_104.c
diff -u src/tests/usr.bin/xlint/lint1/msg_104.c:1.2 src/tests/usr.bin/xlint/lint1/msg_104.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_104.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_104.c	Sun Jul  4 17:01:58 2021
@@ -1,7 +1,17 @@
-/*	$NetBSD: msg_104.c,v 1.2 2021/02/21 09:07:58 rillig Exp $	*/
+/*	$NetBSD: msg_104.c,v 1.3 2021/07/04 17:01:58 rillig Exp $	*/
 # 3 "msg_104.c"
 
-// Test for message: left operand of '->' must be pointer to struct/union not %s [104]
+// Test for message: left operand of '->' must be pointer to struct or union, not '%s' [104]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+struct point {
+	int x, y;
+};
+
+/* ARGSUSED */
+void
+test(struct point pt, struct point *ptr)
+{
+	/* expect+1: left operand of '->' must be pointer to struct or union, not 'struct point' [104] */
+	pt->x = 0;
+	ptr->y = 0;
+}
Index: src/tests/usr.bin/xlint/lint1/msg_104.exp
diff -u src/tests/usr.bin/xlint/lint1/msg_104.exp:1.2 src/tests/usr.bin/xlint/lint1/msg_104.exp:1.3
--- src/tests/usr.bin/xlint/lint1/msg_104.exp:1.2	Sun Mar 21 20:44:59 2021
+++ src/tests/usr.bin/xlint/lint1/msg_104.exp	Sun Jul  4 17:01:58 2021
@@ -1 +1 @@
-msg_104.c(6): error: syntax error ':' [249]
+msg_104.c(15): error: left operand of '->' must be pointer to struct or union, not 'struct point' [104]

Index: src/usr.bin/xlint/lint1/err.c
diff -u src/usr.bin/xlint/lint1/err.c:1.124 src/usr.bin/xlint/lint1/err.c:1.125
--- src/usr.bin/xlint/lint1/err.c:1.124	Sun Jul  4 13:31:10 2021
+++ src/usr.bin/xlint/lint1/err.c	Sun Jul  4 17:01:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: err.c,v 1.124 2021/07/04 13:31:10 rillig Exp $	*/
+/*	$NetBSD: err.c,v 1.125 2021/07/04 17:01:58 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.124 2021/07/04 13:31:10 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.125 2021/07/04 17:01:58 rillig Exp $");
 #endif
 
 #include <sys/types.h>
@@ -157,8 +157,8 @@ const char *const msgs[] = {
 	"unary + is illegal in traditional C",			      /* 100 */
 	"type '%s' does not have member '%s'",			      /* 101 */
 	"illegal member use: %s",				      /* 102 */
-	"left operand of '.' must be struct/union object",	      /* 103 */
-	"left operand of '->' must be pointer to struct/union not %s",/* 104 */
+	"left operand of '.' must be struct or union, not '%s'",      /* 103 */
+	"left operand of '->' must be pointer to struct or union, not '%s'", /* 104 */
 	"non-unique member requires struct/union %s",		      /* 105 */
 	"left operand of '->' must be pointer",			      /* 106 */
 	"operands of '%s' have incompatible types (%s != %s)",	      /* 107 */

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.309 src/usr.bin/xlint/lint1/tree.c:1.310
--- src/usr.bin/xlint/lint1/tree.c:1.309	Sun Jul  4 16:44:13 2021
+++ src/usr.bin/xlint/lint1/tree.c	Sun Jul  4 17:01:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.309 2021/07/04 16:44:13 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.310 2021/07/04 17:01:58 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.309 2021/07/04 16:44:13 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.310 2021/07/04 17:01:58 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -457,11 +457,11 @@ struct_or_union_member(tnode_t *tn, op_t
 	if (eq) {
 		if (op == POINT) {
 			if (tflag) {
-				/* left operand of '.' must be struct/... */
-				warning(103);
+				/* left operand of '.' must be struct ... */
+				warning(103, type_name(tn->tn_type));
 			} else {
-				/* left operand of '.' must be struct/... */
-				error(103);
+				/* left operand of '.' must be struct ... */
+				error(103, type_name(tn->tn_type));
 			}
 		} else {
 			if (tflag && tn->tn_type->t_tspec == PTR) {

Reply via email to