Source-Changes-HG archive

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

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: test all combinations ...



details:   https://anonhg.NetBSD.org/src/rev/6061df8e6a11
branches:  trunk
changeset: 377308:6061df8e6a11
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 07 00:25:23 2023 +0000

description:
tests/lint: test all combinations of {func,obj}_{decl,def}

For a non-static function definition that is not declared in a header,
lint doesn't currently warn.  The previous test didn't notice this.

diffstat:

 tests/usr.bin/xlint/lint1/msg_351.c |  107 ++++++++++++++++++++++++++---------
 1 files changed, 78 insertions(+), 29 deletions(-)

diffs (136 lines):

diff -r 89437e1daa14 -r 6061df8e6a11 tests/usr.bin/xlint/lint1/msg_351.c
--- a/tests/usr.bin/xlint/lint1/msg_351.c       Fri Jul 07 00:20:39 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_351.c       Fri Jul 07 00:25:23 2023 +0000
@@ -1,54 +1,103 @@
-/*     $NetBSD: msg_351.c,v 1.5 2023/06/28 17:53:21 rillig Exp $       */
+/*     $NetBSD: msg_351.c,v 1.6 2023/07/07 00:25:23 rillig Exp $       */
 # 3 "msg_351.c"
 
 // Test for message 351: missing%s header declaration for '%s' [351]
 
 /*
- * Warn about variable definitions or function definitions that are visible
- * outside the current translation unit but do not have a previous
+ * Warn about declarations or definitions for functions or objects 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.
+ * objects, the diagnostic omits 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: missing header declaration for 'explicitly_extern_function' [351] */
-extern void explicitly_extern_function(void);
+/* expect+1: warning: missing header declaration for 'func_decl' [351] */
+void func_decl(void);
+/* expect+1: warning: missing header declaration for 'extern_func_decl' [351] */
+extern void extern_func_decl(void);
+static int static_func_decl(void);
+
+// TODO: missing header declaration
+void
+func_def(void)
+{
+}
 
-/* expect+1: warning: missing 'extern' header declaration for 'definition' [351] */
-int definition;
-/* 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;
+// TODO: missing header declaration
+extern void
+extern_func_def(void)
+{
+}
+
+/* expect+2: warning: static function 'static_func_def' unused [236] */
+static void
+static_func_def(void)
+{
+}
+
+/* expect+1: warning: missing 'extern' header declaration for 'obj_decl' [351] */
+extern int obj_decl;
+/* expect+1: warning: missing 'extern' header declaration for 'obj_def' [351] */
+int obj_def;
+static int static_obj_def;
 
 
 # 18 "header.h" 1 3 4
-static int static_def;
-int external_def;
-extern int external_ref;
+
+void func_decl(void);
+extern void extern_func_decl(void);
+static int static_func_decl(void);
+
+void func_def(void);
+extern void extern_func_def(void);
+static void static_func_def(void);
 
-static int static_func_def(void);
-int extern_func_decl(void);
-extern int extern_func_decl_verbose(void);
+void func_def_ok(void);
+extern void extern_func_def_ok(void);
+static void static_func_def_ok(void);
+
+extern int obj_decl;
+int obj_def;
+static int static_obj_def;
+
+# 70 "msg_351.c" 2
+
+void func_decl(void);
+extern void extern_func_decl(void);
+/* expect+1: warning: static function 'static_func_decl' declared but not defined [290] */
+static int static_func_decl(void);
 
-# 43 "msg_351.c" 2
-/* expect+1: warning: static variable 'static_def' unused [226] */
-static int static_def;
-int external_def;
-extern int external_ref;
+void
+func_def_ok(void)
+{
+}
+
+extern void
+extern_func_def_ok(void)
+{
+}
 
-/* expect+1: warning: static function 'static_func_def' declared but not defined [290] */
-static int static_func_def(void);
-int extern_func_decl(void);
-extern int extern_func_decl_verbose(void);
+/* expect+2: warning: static function 'static_func_def_ok' unused [236] */
+static void
+static_func_def_ok(void)
+{
+}
 
+extern int obj_decl;
+int obj_def;
+/* expect+1: warning: static variable 'static_obj_def' unused [226] */
+static int static_obj_def;
+
+
+/*
+ * Do not warn about the temporary identifier generated for the object from the
+ * compound literal.
+ */
 /* expect+1: warning: missing 'extern' header declaration for 'dbl_ptr' [351] */
 double *dbl_ptr = &(double) { 0.0 };



Home | Main Index | Thread Index | Old Index