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: add type information to message ab...
details: https://anonhg.NetBSD.org/src/rev/c488593a00d0
branches: trunk
changeset: 984838:c488593a00d0
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Jul 25 10:39:10 2021 +0000
description:
lint: add type information to message about invalid cast
This probably doesn't matter in practice since the compiler is supposed
to catch this kind of error. Adding the type information mainly ensures
that parsing abstract type names works as specified.
diffstat:
tests/usr.bin/xlint/lint1/msg_147.c | 7 +++----
tests/usr.bin/xlint/lint1/msg_147.exp | 2 +-
usr.bin/xlint/lint1/err.c | 6 +++---
usr.bin/xlint/lint1/tree.c | 27 ++++++++++++---------------
4 files changed, 19 insertions(+), 23 deletions(-)
diffs (116 lines):
diff -r c6589d57e2a7 -r c488593a00d0 tests/usr.bin/xlint/lint1/msg_147.c
--- a/tests/usr.bin/xlint/lint1/msg_147.c Sun Jul 25 10:26:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_147.c Sun Jul 25 10:39:10 2021 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: msg_147.c,v 1.3 2021/07/25 10:26:46 rillig Exp $ */
+/* $NetBSD: msg_147.c,v 1.4 2021/07/25 10:39:10 rillig Exp $ */
# 3 "msg_147.c"
-// Test for message: invalid cast expression [147]
+// Test for message: invalid cast from '%s' to '%s' [147]
// The type name 'int(int)' is a 'function(int) returning int'.
void take(int(int));
@@ -10,7 +10,6 @@
void
call_take(int (*ptr)(int))
{
- /* XXX: That's a little too unspecific. */
- /* expect+1: error: invalid cast expression [147] */
+ /* expect+1: error: invalid cast from 'pointer to function(int) returning int' to 'function(int) returning int' [147] */
take((int(int))ptr);
}
diff -r c6589d57e2a7 -r c488593a00d0 tests/usr.bin/xlint/lint1/msg_147.exp
--- a/tests/usr.bin/xlint/lint1/msg_147.exp Sun Jul 25 10:26:46 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_147.exp Sun Jul 25 10:39:10 2021 +0000
@@ -1,1 +1,1 @@
-msg_147.c(15): error: invalid cast expression [147]
+msg_147.c(14): error: invalid cast from 'pointer to function(int) returning int' to 'function(int) returning int' [147]
diff -r c6589d57e2a7 -r c488593a00d0 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Sun Jul 25 10:26:46 2021 +0000
+++ b/usr.bin/xlint/lint1/err.c Sun Jul 25 10:39:10 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.130 2021/07/15 20:05:49 rillig Exp $ */
+/* $NetBSD: err.c,v 1.131 2021/07/25 10:39:10 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.130 2021/07/15 20:05:49 rillig Exp $");
+__RCSID("$NetBSD: err.c,v 1.131 2021/07/25 10:39:10 rillig Exp $");
#endif
#include <sys/types.h>
@@ -201,7 +201,7 @@
"cannot take size/alignment of function", /* 144 */
"cannot take size/alignment of bit-field", /* 145 */
"cannot take size/alignment of void", /* 146 */
- "invalid cast expression", /* 147 */
+ "invalid cast from '%s' to '%s'", /* 147 */
"improper cast of void expression", /* 148 */
"illegal function (type %s)", /* 149 */
"argument mismatch: %d arg%s passed, %d expected", /* 150 */
diff -r c6589d57e2a7 -r c488593a00d0 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Sun Jul 25 10:26:46 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c Sun Jul 25 10:39:10 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.318 2021/07/20 19:44:36 rillig Exp $ */
+/* $NetBSD: tree.c,v 1.319 2021/07/25 10:39:10 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.318 2021/07/20 19:44:36 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.319 2021/07/25 10:39:10 rillig Exp $");
#endif
#include <float.h>
@@ -3423,15 +3423,10 @@
error(329, type_name(tn->tn_type), type_name(tp));
return NULL;
} else if (nt == STRUCT || nt == ARRAY || nt == FUNC) {
- if (!Sflag || nt == ARRAY || nt == FUNC) {
- /* invalid cast expression */
- error(147);
- return NULL;
- }
+ if (!Sflag || nt == ARRAY || nt == FUNC)
+ goto invalid_cast;
} else if (ot == STRUCT || ot == UNION) {
- /* invalid cast expression */
- error(147);
- return NULL;
+ goto invalid_cast;
} else if (ot == VOID) {
/* improper cast of void expression */
error(148);
@@ -3448,16 +3443,18 @@
/* cast discards 'const' from type '%s' */
warning(275, type_name(tn->tn_type));
}
- } else {
- /* invalid cast expression */
- error(147);
- return NULL;
- }
+ } else
+ goto invalid_cast;
tn = convert(CVT, 0, tp, tn);
tn->tn_cast = true;
return tn;
+
+invalid_cast:
+ /* invalid cast from '%s' to '%s' */
+ error(147, type_name(tn->tn_type), type_name(tp));
+ return NULL;
}
/*
Home |
Main Index |
Thread Index |
Old Index