From d2e28e75c8d813f582a8bdbde3b94f1f51743b26 Mon Sep 17 00:00:00 2001 From: rillig Date: Fri, 7 Jul 2023 00:25:23 +0000 Subject: 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. --- tests/usr.bin/xlint/lint1/msg_351.c | 107 ++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 29 deletions(-) diff --git a/tests/usr.bin/xlint/lint1/msg_351.c b/tests/usr.bin/xlint/lint1/msg_351.c index 7b23376ec6e..f6842eab1ec 100644 --- a/tests/usr.bin/xlint/lint1/msg_351.c +++ b/tests/usr.bin/xlint/lint1/msg_351.c @@ -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); -/* 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 +void +func_def(void) +{ +} + +// 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; -static int static_func_def(void); -int extern_func_decl(void); -extern int extern_func_decl_verbose(void); +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); + +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 -# 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_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); -/* 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); +void +func_def_ok(void) +{ +} +extern void +extern_func_def_ok(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 }; -- cgit