Module Name: src Committed By: rillig Date: Tue Apr 25 19:00:57 UTC 2023
Modified Files: src/tests/usr.bin/xlint/lint1: msg_351.c src/usr.bin/xlint/lint1: decl.c err.c Log Message: lint: reword message for missing declaration in header Suggested by Christos. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_351.c cvs rdiff -u -r1.309 -r1.310 src/usr.bin/xlint/lint1/decl.c cvs rdiff -u -r1.194 -r1.195 src/usr.bin/xlint/lint1/err.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/usr.bin/xlint/lint1/msg_351.c diff -u src/tests/usr.bin/xlint/lint1/msg_351.c:1.3 src/tests/usr.bin/xlint/lint1/msg_351.c:1.4 --- src/tests/usr.bin/xlint/lint1/msg_351.c:1.3 Sat Apr 22 20:27:09 2023 +++ src/tests/usr.bin/xlint/lint1/msg_351.c Tue Apr 25 19:00:57 2023 @@ -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 }; Index: src/usr.bin/xlint/lint1/decl.c diff -u src/usr.bin/xlint/lint1/decl.c:1.309 src/usr.bin/xlint/lint1/decl.c:1.310 --- src/usr.bin/xlint/lint1/decl.c:1.309 Sat Apr 22 20:27:09 2023 +++ src/usr.bin/xlint/lint1/decl.c Tue Apr 25 19:00:57 2023 @@ -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 *sy 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); } } Index: src/usr.bin/xlint/lint1/err.c diff -u src/usr.bin/xlint/lint1/err.c:1.194 src/usr.bin/xlint/lint1/err.c:1.195 --- src/usr.bin/xlint/lint1/err.c:1.194 Sun Apr 23 09:04:44 2023 +++ src/usr.bin/xlint/lint1/err.c Tue Apr 25 19:00:57 2023 @@ -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 */ };