lint: add query for parenthesized return value
This commit is contained in:
parent
e7d3b23c6b
commit
408e7ca205
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: queries.c,v 1.11 2023/03/31 13:03:05 rillig Exp $ */
|
||||
/* $NetBSD: queries.c,v 1.12 2023/04/15 11:34:45 rillig Exp $ */
|
||||
# 3 "queries.c"
|
||||
|
||||
/*
|
||||
|
@ -15,7 +15,7 @@
|
|||
* such as casts between arithmetic types.
|
||||
*/
|
||||
|
||||
/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8 -X 351 */
|
||||
/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9 -X 351 */
|
||||
|
||||
typedef unsigned char u8_t;
|
||||
typedef unsigned short u16_t;
|
||||
|
@ -310,6 +310,49 @@ Q8(void)
|
|||
u16 = 0000644;
|
||||
}
|
||||
|
||||
int
|
||||
Q9(int x)
|
||||
{
|
||||
switch (x) {
|
||||
case 0:
|
||||
return 0;
|
||||
case 1:
|
||||
/* expect+1: parenthesized return value [Q9] */
|
||||
return (0);
|
||||
case 2:
|
||||
return +(0);
|
||||
case 3:
|
||||
return -(13);
|
||||
case 4:
|
||||
/* expect+1: parenthesized return value [Q9] */
|
||||
return (0), (1);
|
||||
case 5:
|
||||
/* expect+1: parenthesized return value [Q9] */
|
||||
return (0, 1);
|
||||
case 6:
|
||||
return 0, 1;
|
||||
case 7:
|
||||
/* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */
|
||||
return 0.0;
|
||||
case 8:
|
||||
/* expect+2: parenthesized return value [Q9] */
|
||||
/* expect+1: implicit conversion from floating point 'double' to integer 'int' [Q1] */
|
||||
return (0.0);
|
||||
case 9:
|
||||
return
|
||||
# 344 "queries.c" 3 4
|
||||
((void *)0)
|
||||
# 346 "queries.c"
|
||||
/* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */
|
||||
;
|
||||
case 10:
|
||||
/* expect+1: warning: illegal combination of integer 'int' and pointer 'pointer to void' [183] */
|
||||
return (void *)(0);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Since queries do not affect the exit status, force a warning to make this
|
||||
* test conform to the general expectation that a test that produces output
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: err.c,v 1.192 2023/03/31 13:03:05 rillig Exp $ */
|
||||
/* $NetBSD: err.c,v 1.193 2023/04/15 11:34:45 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Jochen Pohl
|
||||
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID)
|
||||
__RCSID("$NetBSD: err.c,v 1.192 2023/03/31 13:03:05 rillig Exp $");
|
||||
__RCSID("$NetBSD: err.c,v 1.193 2023/04/15 11:34:45 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
@ -699,6 +699,7 @@ static const char *queries[] = {
|
|||
"no-op cast from '%s' to '%s'", /* Q6 */
|
||||
"redundant cast from '%s' to '%s' before assignment", /* Q7 */
|
||||
"octal number '%.*s'", /* Q8 */
|
||||
"parenthesized return value", /* Q9 */
|
||||
};
|
||||
|
||||
bool any_query_enabled; /* for optimizing non-query scenarios */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: func.c,v 1.152 2023/04/15 10:32:46 rillig Exp $ */
|
||||
/* $NetBSD: func.c,v 1.153 2023/04/15 11:34:45 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Jochen Pohl
|
||||
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID)
|
||||
__RCSID("$NetBSD: func.c,v 1.152 2023/04/15 10:32:46 rillig Exp $");
|
||||
__RCSID("$NetBSD: func.c,v 1.153 2023/04/15 11:34:45 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -1047,9 +1047,24 @@ do_continue(void)
|
|||
set_reached(false);
|
||||
}
|
||||
|
||||
static bool
|
||||
is_parenthesized(const tnode_t *tn)
|
||||
{
|
||||
|
||||
while (!tn->tn_parenthesized && tn->tn_op == COMMA)
|
||||
tn = tn->tn_right;
|
||||
return tn->tn_parenthesized && !tn->tn_sys;
|
||||
}
|
||||
|
||||
static void
|
||||
check_return_value(bool sys, tnode_t *tn)
|
||||
{
|
||||
|
||||
if (any_query_enabled && is_parenthesized(tn)) {
|
||||
/* parenthesized return value */
|
||||
query_message(9);
|
||||
}
|
||||
|
||||
/* Create a temporary node for the left side */
|
||||
tnode_t *ln = expr_zero_alloc(sizeof(*ln));
|
||||
ln->tn_op = NAME;
|
||||
|
|
Loading…
Reference in New Issue