Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: reword message for missing declara...



details:   https://anonhg.NetBSD.org/src/rev/17121c1247d8
branches:  trunk
changeset: 374478:17121c1247d8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Apr 25 19:00:57 2023 +0000

description:
lint: reword message for missing declaration in header

Suggested by Christos.

diffstat:

 tests/usr.bin/xlint/lint1/msg_351.c |  28 +++++++++++++++++++++-------
 usr.bin/xlint/lint1/decl.c          |   9 +++++----
 usr.bin/xlint/lint1/err.c           |   6 +++---
 3 files changed, 29 insertions(+), 14 deletions(-)

diffs (104 lines):

diff -r 5330810b53a8 -r 17121c1247d8 tests/usr.bin/xlint/lint1/msg_351.c
--- a/tests/usr.bin/xlint/lint1/msg_351.c       Tue Apr 25 17:51:32 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_351.c       Tue Apr 25 19:00:57 2023 +0000
@@ -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 };
diff -r 5330810b53a8 -r 17121c1247d8 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Tue Apr 25 17:51:32 2023 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Tue Apr 25 19:00:57 2023 +0000
@@ -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);
        }
 }
 
diff -r 5330810b53a8 -r 17121c1247d8 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Tue Apr 25 17:51:32 2023 +0000
+++ b/usr.bin/xlint/lint1/err.c Tue Apr 25 19:00:57 2023 +0000
@@ -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 */
 };
 



Home | Main Index | Thread Index | Old Index