Module Name:    src
Committed By:   rillig
Date:           Mon Mar 10 22:35:02 UTC 2025

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_127.c msg_286.c msg_287.c
        src/usr.bin/xlint/lint1: decl.c func.c

Log Message:
lint: in C99 mode and later, warn about non-prototype functions

Suggested by Christos Zoulas.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_127.c
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_286.c \
    src/tests/usr.bin/xlint/lint1/msg_287.c
cvs rdiff -u -r1.413 -r1.414 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.191 -r1.192 src/usr.bin/xlint/lint1/func.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_127.c
diff -u src/tests/usr.bin/xlint/lint1/msg_127.c:1.5 src/tests/usr.bin/xlint/lint1/msg_127.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_127.c:1.5	Mon Feb 24 19:56:27 2025
+++ src/tests/usr.bin/xlint/lint1/msg_127.c	Mon Mar 10 22:35:02 2025
@@ -1,10 +1,11 @@
-/*	$NetBSD: msg_127.c,v 1.5 2025/02/24 19:56:27 rillig Exp $	*/
+/*	$NetBSD: msg_127.c,v 1.6 2025/03/10 22:35:02 rillig Exp $	*/
 # 3 "msg_127.c"
 
 /* Test for message: '&' before array or function: ignored [127] */
+/* This message is not used. */
 /*
- * This message is no longer used, as it contradicts all C standards and is
- * not mentioned in K&R 1978 either.
+ * This message contradicts all C standards and is not mentioned in K&R 1978
+ * either.
  */
 
 /* lint1-extra-flags: -t */

Index: src/tests/usr.bin/xlint/lint1/msg_286.c
diff -u src/tests/usr.bin/xlint/lint1/msg_286.c:1.3 src/tests/usr.bin/xlint/lint1/msg_286.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_286.c:1.3	Thu Jun 16 21:24:41 2022
+++ src/tests/usr.bin/xlint/lint1/msg_286.c	Mon Mar 10 22:35:02 2025
@@ -1,8 +1,27 @@
-/*	$NetBSD: msg_286.c,v 1.3 2022/06/16 21:24:41 rillig Exp $	*/
+/*	$NetBSD: msg_286.c,v 1.4 2025/03/10 22:35:02 rillig Exp $	*/
 # 3 "msg_286.c"
 
 // Test for message: function definition is not a prototype [286]
 
-/* expect+1: error: syntax error ':' [249] */
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+/* lint1-extra-flags: -h -X 351 */
+
+/* expect+1: warning: function declaration is not a prototype [287] */
+void no_prototype_declaration();
+void prototype_declaration(void);
+
+void
+no_prototype_definition()
+/* expect+1: warning: function definition is not a prototype [286] */
+{
+}
+
+void
+prototype_definition(void)
+{
+}
+
+int
+main()
+/* expect+1: warning: function definition is not a prototype [286] */
+{
+}
Index: src/tests/usr.bin/xlint/lint1/msg_287.c
diff -u src/tests/usr.bin/xlint/lint1/msg_287.c:1.3 src/tests/usr.bin/xlint/lint1/msg_287.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_287.c:1.3	Thu Jun 16 21:24:41 2022
+++ src/tests/usr.bin/xlint/lint1/msg_287.c	Mon Mar 10 22:35:02 2025
@@ -1,8 +1,18 @@
-/*	$NetBSD: msg_287.c,v 1.3 2022/06/16 21:24:41 rillig Exp $	*/
+/*	$NetBSD: msg_287.c,v 1.4 2025/03/10 22:35:02 rillig Exp $	*/
 # 3 "msg_287.c"
 
 // Test for message: function declaration is not a prototype [287]
 
-/* expect+1: error: syntax error ':' [249] */
-TODO: "Add example code that triggers the above message."
-TODO: "Add example code that almost triggers the above message."
+/* lint1-extra-flags: -h -X 351 */
+
+/* expect+1: warning: function declaration is not a prototype [287] */
+void no_prototype_declaration();
+void prototype_declaration(void);
+
+/* expect+1: warning: function declaration is not a prototype [287] */
+typedef void (no_prototype_typedef)();
+typedef void (prototype_typedef)(void);
+
+/* expect+1: warning: function declaration is not a prototype [287] */
+int no_prototype_sizeof[sizeof(void (*)())];
+int prototype_sizeof[sizeof(void (*)(void))];

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.413 src/usr.bin/xlint/lint1/decl.c:1.414
--- src/usr.bin/xlint/lint1/decl.c:1.413	Thu Feb 27 06:48:28 2025
+++ src/usr.bin/xlint/lint1/decl.c	Mon Mar 10 22:35:02 2025
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.413 2025/02/27 06:48:28 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.414 2025/03/10 22:35:02 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.413 2025/02/27 06:48:28 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.414 2025/03/10 22:35:02 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -885,8 +885,7 @@ check_type(sym_t *sym)
 		 */
 		if (t == FUNC && !tp->t_proto &&
 		    !(to == NO_TSPEC && sym->s_osdef)) {
-			/* TODO: Make this an error in C99 mode as well. */
-			if (!allow_trad && !allow_c99 && hflag)
+			if (!allow_trad && hflag)
 				/* function declaration is not a prototype */
 				warning(287);
 		}

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.191 src/usr.bin/xlint/lint1/func.c:1.192
--- src/usr.bin/xlint/lint1/func.c:1.191	Sat Nov 30 10:43:49 2024
+++ src/usr.bin/xlint/lint1/func.c	Mon Mar 10 22:35:02 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.191 2024/11/30 10:43:49 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.192 2025/03/10 22:35:02 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID)
-__RCSID("$NetBSD: func.c,v 1.191 2024/11/30 10:43:49 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.192 2025/03/10 22:35:02 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -312,9 +312,8 @@ begin_function(sym_t *fsym)
 	}
 
 	if (fsym->s_osdef && !fsym->s_type->t_proto) {
-		/* TODO: Make this an error in C99 mode as well. */
-		if (!allow_trad && !allow_c99 && hflag &&
-		    strcmp(fsym->s_name, "main") != 0)
+		if (!allow_trad && hflag &&
+		    (allow_c99 || strcmp(fsym->s_name, "main") != 0))
 			/* function definition is not a prototype */
 			warning(286);
 	}

Reply via email to