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

This commit is contained in:
rillig 2021-07-04 17:01:58 +00:00
parent 090f19d307
commit 8b62008a54
8 changed files with 46 additions and 29 deletions

View File

@ -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 struct point pt)
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 */

View File

@ -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]

View File

@ -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;
}

View File

@ -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]

View File

@ -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;
}

View File

@ -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]

View File

@ -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 */

View File

@ -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 op, sym_t *msym)
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) {