Module Name: src Committed By: rillig Date: Fri Jul 7 00:25:23 UTC 2023
Modified Files: src/tests/usr.bin/xlint/lint1: msg_351.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_351.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.5 src/tests/usr.bin/xlint/lint1/msg_351.c:1.6 --- src/tests/usr.bin/xlint/lint1/msg_351.c:1.5 Wed Jun 28 17:53:21 2023 +++ src/tests/usr.bin/xlint/lint1/msg_351.c Fri Jul 7 00:25:23 2023 @@ -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 '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; +/* 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) +{ +} + +// 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); - -# 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; - -/* 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_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 + +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); + +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 };