xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_351.c (revision 9e211f359920a7b95ff05505ca6ee27fa088acb5)
1 /*	$NetBSD: msg_351.c,v 1.8 2024/03/01 17:22:55 rillig Exp $	*/
2 # 3 "msg_351.c"
3 
4 // Test for message: missing%s header declaration for '%s' [351]
5 
6 /*
7  * Warn about declarations or definitions for functions or objects that are
8  * visible outside the current translation unit but do not have a previous
9  * declaration in a header file.
10  *
11  * All symbols that are used across translation units should be declared in a
12  * header file, to ensure consistent types.
13  *
14  * Since the storage class 'extern' is redundant for functions but not for
15  * objects, the diagnostic omits it for functions.
16  *
17  * https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmissing-declarations
18  */
19 
20 /* expect+1: warning: missing header declaration for 'func_decl' [351] */
21 void func_decl(void);
22 /* expect+1: warning: missing header declaration for 'extern_func_decl' [351] */
23 extern void extern_func_decl(void);
24 static int static_func_decl(void);
25 
26 /* expect+3: warning: missing header declaration for 'func_def' [351] */
27 void
func_def(void)28 func_def(void)
29 {
30 }
31 
32 /* expect+3: warning: missing header declaration for 'extern_func_def' [351] */
33 extern void
extern_func_def(void)34 extern_func_def(void)
35 {
36 }
37 
38 /* expect+2: warning: static function 'static_func_def' unused [236] */
39 static void
static_func_def(void)40 static_func_def(void)
41 {
42 }
43 
44 /* expect+1: warning: missing 'extern' header declaration for 'obj_decl' [351] */
45 extern int obj_decl;
46 /* expect+1: warning: missing 'extern' header declaration for 'obj_def' [351] */
47 int obj_def;
48 static int static_obj_def;
49 
50 
51 # 18 "header.h" 1 3 4
52 
53 void func_decl(void);
54 extern void extern_func_decl(void);
55 static int static_func_decl(void);
56 
57 void func_def(void);
58 extern void extern_func_def(void);
59 static void static_func_def(void);
60 
61 void func_def_ok(void);
62 extern void extern_func_def_ok(void);
63 static void static_func_def_ok(void);
64 
65 extern int obj_decl;
66 int obj_def;
67 static int static_obj_def;
68 
69 # 70 "msg_351.c" 2
70 
71 void func_decl(void);
72 extern void extern_func_decl(void);
73 /* expect+1: warning: static function 'static_func_decl' declared but not defined [290] */
74 static int static_func_decl(void);
75 
76 void
func_def_ok(void)77 func_def_ok(void)
78 {
79 }
80 
81 extern void
extern_func_def_ok(void)82 extern_func_def_ok(void)
83 {
84 }
85 
86 /* expect+2: warning: static function 'static_func_def_ok' unused [236] */
87 static void
static_func_def_ok(void)88 static_func_def_ok(void)
89 {
90 }
91 
92 extern int obj_decl;
93 int obj_def;
94 /* expect+1: warning: static variable 'static_obj_def' unused [226] */
95 static int static_obj_def;
96 
97 
98 /*
99  * Do not warn about the temporary identifier generated for the object from the
100  * compound literal.
101  */
102 /* expect+1: warning: missing 'extern' header declaration for 'dbl_ptr' [351] */
103 double *dbl_ptr = &(double) { 0.0 };
104