lint: make messages for incompatible pointers more specific
Message 153 didn't state obviously which of the pointer types was the one before conversion (or cast) and which was the resulting type. Message 229 didn't have any type information at all.
This commit is contained in:
parent
033a381e0d
commit
4b52b11627
|
@ -1,15 +1,22 @@
|
|||
/* $NetBSD: msg_153.c,v 1.3 2021/02/28 00:52:16 rillig Exp $ */
|
||||
/* $NetBSD: msg_153.c,v 1.4 2021/02/28 01:06:57 rillig Exp $ */
|
||||
# 3 "msg_153.c"
|
||||
|
||||
// Test for message: argument has incompatible pointer type, arg #%d (%s != %s) [153]
|
||||
// Test for message: converting '%s' to incompatible '%s' for argument %d [153]
|
||||
|
||||
|
||||
typedef double (*unary_operator)(double);
|
||||
|
||||
void sink_unary_operator(unary_operator);
|
||||
void sink_function_pointer(unary_operator);
|
||||
void sink_int_pointer(int *);
|
||||
|
||||
void
|
||||
example(int x)
|
||||
to_function_pointer(int *x)
|
||||
{
|
||||
sink_unary_operator(&x);
|
||||
sink_function_pointer(x);
|
||||
}
|
||||
|
||||
void
|
||||
to_int_pointer(unary_operator op)
|
||||
{
|
||||
sink_int_pointer(op);
|
||||
}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
msg_153.c(14): warning: argument has incompatible pointer type, arg #1 (pointer to function(double) returning double != pointer to int) [153]
|
||||
msg_153.c(15): warning: converting 'pointer to int' to incompatible 'pointer to function(double) returning double' for argument 1 [153]
|
||||
msg_153.c(21): warning: converting 'pointer to function(double) returning double' to incompatible 'pointer to int' for argument 1 [153]
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
/* $NetBSD: msg_229.c,v 1.3 2021/02/28 00:52:16 rillig Exp $ */
|
||||
/* $NetBSD: msg_229.c,v 1.4 2021/02/28 01:06:57 rillig Exp $ */
|
||||
# 3 "msg_229.c"
|
||||
|
||||
// Test for message: questionable conversion of function pointer [229]
|
||||
// Test for message: converting '%s' to '%s' is questionable [229]
|
||||
|
||||
typedef double (*unary_operator)(double);
|
||||
|
||||
int *
|
||||
example(unary_operator op)
|
||||
to_int_pointer(unary_operator op)
|
||||
{
|
||||
return (int *)op;
|
||||
}
|
||||
|
||||
unary_operator
|
||||
to_function_pointer(int *p)
|
||||
{
|
||||
return (unary_operator)p;
|
||||
}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
msg_229.c(11): warning: questionable conversion of function pointer [229]
|
||||
msg_229.c(11): warning: converting 'pointer to function(double) returning double' to 'pointer to int' is questionable [229]
|
||||
msg_229.c(17): warning: converting 'pointer to int' to 'pointer to function(double) returning double' is questionable [229]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: err.c,v 1.82 2021/02/28 00:40:22 rillig Exp $ */
|
||||
/* $NetBSD: err.c,v 1.83 2021/02/28 01:06:57 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.82 2021/02/28 00:40:22 rillig Exp $");
|
||||
__RCSID("$NetBSD: err.c,v 1.83 2021/02/28 01:06:57 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -212,7 +212,7 @@ const char *msgs[] = {
|
|||
"argument mismatch: %d arg%s passed, %d expected", /* 150 */
|
||||
"void expressions may not be arguments, arg #%d", /* 151 */
|
||||
"argument cannot have unknown size, arg #%d", /* 152 */
|
||||
"argument has incompatible pointer type, arg #%d (%s != %s)", /* 153 */
|
||||
"converting '%s' to incompatible '%s' for argument %d", /* 153 */
|
||||
"illegal combination of %s (%s) and %s (%s), arg #%d", /* 154 */
|
||||
"argument is incompatible with prototype, arg #%d", /* 155 */
|
||||
"enum type mismatch, arg #%d (%s != %s)", /* 156 */
|
||||
|
@ -288,7 +288,7 @@ const char *msgs[] = {
|
|||
"static variable %s unused", /* 226 */
|
||||
"const object %s should have initializer", /* 227 */
|
||||
"function cannot return const or volatile object", /* 228 */
|
||||
"questionable conversion of function pointer", /* 229 */
|
||||
"converting '%s' to '%s' is questionable", /* 229 */
|
||||
"nonportable character comparison, op %s", /* 230 */
|
||||
"argument %s unused in function %s", /* 231 */
|
||||
"label %s unused in function %s", /* 232 */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: tree.c,v 1.222 2021/02/28 00:40:22 rillig Exp $ */
|
||||
/* $NetBSD: tree.c,v 1.223 2021/02/28 01:06:57 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.222 2021/02/28 00:40:22 rillig Exp $");
|
||||
__RCSID("$NetBSD: tree.c,v 1.223 2021/02/28 01:06:57 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <float.h>
|
||||
|
@ -1597,9 +1597,9 @@ check_assign_types_compatible(op_t op, int arg,
|
|||
warning(182, type_name(lstp), type_name(rstp));
|
||||
break;
|
||||
case FARG:
|
||||
/* argument has incompatible pointer type... */
|
||||
/* converting '%s' to incompatible '%s' ... */
|
||||
warning(153,
|
||||
arg, type_name(lstp), type_name(rstp));
|
||||
type_name(rtp), type_name(ltp), arg);
|
||||
break;
|
||||
default:
|
||||
/* operands have incompatible pointer type... */
|
||||
|
@ -1642,8 +1642,8 @@ check_assign_types_compatible(op_t op, int arg,
|
|||
warn_incompatible_pointers(NULL, ltp, rtp);
|
||||
break;
|
||||
case FARG:
|
||||
/* arg. has incomp. pointer type, arg #%d (%s != %s) */
|
||||
warning(153, arg, type_name(ltp), type_name(rtp));
|
||||
/* converting '%s' to incompatible '%s' for ... */
|
||||
warning(153, type_name(rtp), type_name(ltp), arg);
|
||||
break;
|
||||
default:
|
||||
warn_incompatible_pointers(mp, ltp, rtp);
|
||||
|
@ -2238,8 +2238,8 @@ check_pointer_conversion(op_t op, tnode_t *tn, type_t *tp)
|
|||
} else if (nt == FUNC && ot == FUNC) {
|
||||
return;
|
||||
} else if (nt == FUNC || ot == FUNC) {
|
||||
/* questionable conversion of function pointer */
|
||||
warning(229);
|
||||
/* converting '%s' to '%s' is questionable */
|
||||
warning(229, type_name(tn->tn_type), type_name(tp));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue