lint: allow querying for 'static' followed by non-'static' declaration

This commit is contained in:
rillig 2023-12-10 15:29:38 +00:00
parent de4a7516ed
commit 960c22026a
5 changed files with 31 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: queries.c,v 1.19 2023/07/03 15:29:42 rillig Exp $ */
/* $NetBSD: queries.c,v 1.20 2023/12/10 15:29:38 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,9,10,11,12,13,14,15 -X 351 */
/* lint1-extra-flags: -q 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 -X 351 */
typedef unsigned char u8_t;
typedef unsigned short u16_t;
@ -447,6 +447,17 @@ Q15(void)
return 0;
}
/*
* Even though C99 6.2.2p4 allows a 'static' declaration followed by a
* non-'static' declaration, it may look confusing.
*/
static void Q16(void);
/* expect+2: 'Q16' was declared 'static', now non-'static' [Q16] */
/* expect+1: warning: static function 'Q16' unused [236] */
void Q16(void)
{
}
/*
* 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

View File

@ -1,4 +1,4 @@
# $NetBSD: t_usage.sh,v 1.11 2023/08/03 18:48:42 rillig Exp $
# $NetBSD: t_usage.sh,v 1.12 2023/12/10 15:29:38 rillig Exp $
#
# Copyright (c) 2023 The NetBSD Foundation, Inc.
# All rights reserved.
@ -89,13 +89,13 @@ enable_queries_body()
# The largest known query.
atf_check \
"$lint1" -q 15 code.c /dev/null
"$lint1" -q 16 code.c /dev/null
# Larger than the largest known query.
atf_check \
-s 'exit:1' \
-e "inline:lint1: invalid query ID '16'\n" \
"$lint1" -q 16 code.c /dev/null
-e "inline:lint1: invalid query ID '17'\n" \
"$lint1" -q 17 code.c /dev/null
# Whitespace is not allowed before a query ID.
atf_check \

View File

@ -1,4 +1,4 @@
/* $NetBSD: decl.c,v 1.384 2023/12/10 14:59:47 rillig Exp $ */
/* $NetBSD: decl.c,v 1.385 2023/12/10 15:29:38 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID)
__RCSID("$NetBSD: decl.c,v 1.384 2023/12/10 14:59:47 rillig Exp $");
__RCSID("$NetBSD: decl.c,v 1.385 2023/12/10 15:29:38 rillig Exp $");
#endif
#include <sys/param.h>
@ -1430,6 +1430,12 @@ declarator_name(sym_t *sym)
dcs->d_redeclared_symbol = NULL;
} else {
dcs->d_redeclared_symbol = sym;
if (is_query_enabled[16]
&& sym->s_scl == STATIC && dcs->d_scl != STATIC) {
/* '%s' was declared 'static', now non-'static' */
query_message(16, sym->s_name);
print_previous_declaration(sym);
}
sym = pushdown(sym);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: err.c,v 1.220 2023/12/03 18:17:41 rillig Exp $ */
/* $NetBSD: err.c,v 1.221 2023/12/10 15:29:38 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.220 2023/12/03 18:17:41 rillig Exp $");
__RCSID("$NetBSD: err.c,v 1.221 2023/12/10 15:29:38 rillig Exp $");
#endif
#include <limits.h>
@ -714,10 +714,11 @@ static const char *queries[] = {
"redundant 'extern' in function declaration of '%s'", /* Q13 */
"comparison '%s' of 'char' with plain integer %d", /* Q14 */
"implicit conversion from integer 0 to pointer '%s'", /* Q15 */
"'%s' was declared 'static', now non-'static'", /* Q16 */
};
bool any_query_enabled; /* for optimizing non-query scenarios */
static bool is_query_enabled[sizeof(queries) / sizeof(queries[0])];
bool is_query_enabled[sizeof(queries) / sizeof(queries[0])];
void
(query_message)(int query_id, ...)

View File

@ -1,4 +1,4 @@
/* $NetBSD: externs1.h,v 1.208 2023/12/03 18:17:41 rillig Exp $ */
/* $NetBSD: externs1.h,v 1.209 2023/12/10 15:29:38 rillig Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@ -179,6 +179,7 @@ extern bool seen_error;
extern bool seen_warning;
extern int sytxerr;
extern bool any_query_enabled;
extern bool is_query_enabled[];
void msglist(void);
void error_at(int, const pos_t *, ...);