lint: reword message for missing declaration in header

Suggested by Christos.
This commit is contained in:
rillig 2023-04-25 19:00:57 +00:00
parent 4ee547369c
commit 0878a3d7ee
3 changed files with 29 additions and 14 deletions

View File

@ -1,16 +1,30 @@
/* $NetBSD: msg_351.c,v 1.3 2023/04/22 20:27:09 rillig Exp $ */
/* $NetBSD: msg_351.c,v 1.4 2023/04/25 19:00:57 rillig Exp $ */
# 3 "msg_351.c"
// Test for message 351: 'extern' declaration of '%s' outside a header [351]
// Test for message 351: missing%s header declaration for '%s' [351]
/* expect+1: warning: 'extern' declaration of 'implicitly_extern_function' outside a header [351] */
/*
* Warn about variable definitions or function definitions that are visible
* outside the current translation unit but do not have a previous
* declaration in a header file.
*
* All symbols that are used across translation units should be declared in a
* header file, to ensure consistent types.
*
* Since the storage class 'extern' is redundant for functions but not for
* objects, omit it for functions.
*
* https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmissing-declarations
*/
/* expect+1: warning: missing header declaration for 'implicitly_extern_function' [351] */
void implicitly_extern_function(void);
/* expect+1: warning: 'extern' declaration of 'explicitly_extern_function' outside a header [351] */
/* expect+1: warning: missing header declaration for 'explicitly_extern_function' [351] */
extern void explicitly_extern_function(void);
/* expect+1: warning: 'extern' declaration of 'definition' outside a header [351] */
/* expect+1: warning: missing 'extern' header declaration for 'definition' [351] */
int definition;
/* expect+1: warning: 'extern' declaration of 'reference' outside a header [351] */
/* expect+1: warning: missing 'extern' header declaration for 'reference' [351] */
extern int reference;
/* expect+1: warning: static variable 'file_scoped_definition' unused [226] */
static int file_scoped_definition;
@ -36,5 +50,5 @@ static int static_func_def(void);
int extern_func_decl(void);
extern int extern_func_decl_verbose(void);
/* expect+1: warning: 'extern' declaration of 'dbl_ptr' outside a header [351] */
/* expect+1: warning: missing 'extern' header declaration for 'dbl_ptr' [351] */
double *dbl_ptr = &(double) { 0.0 };

View File

@ -1,4 +1,4 @@
/* $NetBSD: decl.c,v 1.309 2023/04/22 20:27:09 rillig Exp $ */
/* $NetBSD: decl.c,v 1.310 2023/04/25 19:00:57 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.309 2023/04/22 20:27:09 rillig Exp $");
__RCSID("$NetBSD: decl.c,v 1.310 2023/04/25 19:00:57 rillig Exp $");
#endif
#include <sys/param.h>
@ -1938,8 +1938,9 @@ check_extern_declaration(const sym_t *sym)
dcs->d_redeclared_symbol == NULL &&
ends_with(curr_pos.p_file, ".c") &&
!ch_isdigit(sym->s_name[0])) { /* see mktempsym */
/* 'extern' declaration of '%s' outside a header */
warning(351, sym->s_name);
/* missing%s header declaration for '%s' */
warning(351, sym->s_type->t_tspec == FUNC ? "" : " 'extern'",
sym->s_name);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: err.c,v 1.194 2023/04/23 09:04:44 rillig Exp $ */
/* $NetBSD: err.c,v 1.195 2023/04/25 19:00:57 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.194 2023/04/23 09:04:44 rillig Exp $");
__RCSID("$NetBSD: err.c,v 1.195 2023/04/25 19:00:57 rillig Exp $");
#endif
#include <limits.h>
@ -406,7 +406,7 @@ static const char *const msgs[] = {
"maximum value %d of '%s' does not match maximum array index %d", /* 348 */
"non type argument to alignof is a GCC extension", /* 349 */
"'_Atomic' requires C11 or later", /* 350 */
"'extern' declaration of '%s' outside a header", /* 351 */
"missing%s header declaration for '%s'", /* 351 */
"nested 'extern' declaration of '%s'", /* 352 */
};