Module Name:    src
Committed By:   rillig
Date:           Sun Aug  6 19:44:50 UTC 2023

Modified Files:
        src/tests/usr.bin/xlint/lint1: c11_generic_expression.c
            d_c99_bool_strict_syshdr.c d_fold_test.c expr_cast.c
            lang_level_c99.c msg_109.c msg_126.c msg_132.c msg_170.c msg_204.c
            msg_214.c
        src/usr.bin/xlint/lint1: func.c

Log Message:
lint: since C99, a non-void function must return a value


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 \
    src/tests/usr.bin/xlint/lint1/c11_generic_expression.c
cvs rdiff -u -r1.21 -r1.22 \
    src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/d_fold_test.c \
    src/tests/usr.bin/xlint/lint1/msg_126.c \
    src/tests/usr.bin/xlint/lint1/msg_170.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/expr_cast.c
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/lang_level_c99.c
cvs rdiff -u -r1.6 -r1.7 src/tests/usr.bin/xlint/lint1/msg_109.c
cvs rdiff -u -r1.31 -r1.32 src/tests/usr.bin/xlint/lint1/msg_132.c
cvs rdiff -u -r1.10 -r1.11 src/tests/usr.bin/xlint/lint1/msg_204.c
cvs rdiff -u -r1.5 -r1.6 src/tests/usr.bin/xlint/lint1/msg_214.c
cvs rdiff -u -r1.173 -r1.174 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/c11_generic_expression.c
diff -u src/tests/usr.bin/xlint/lint1/c11_generic_expression.c:1.18 src/tests/usr.bin/xlint/lint1/c11_generic_expression.c:1.19
--- src/tests/usr.bin/xlint/lint1/c11_generic_expression.c:1.18	Sun Jul  9 11:18:55 2023
+++ src/tests/usr.bin/xlint/lint1/c11_generic_expression.c	Sun Aug  6 19:44:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: c11_generic_expression.c,v 1.18 2023/07/09 11:18:55 rillig Exp $	*/
+/*	$NetBSD: c11_generic_expression.c,v 1.19 2023/08/06 19:44:50 rillig Exp $	*/
 # 3 "c11_generic_expression.c"
 
 /* lint1-extra-flags: -X 351 */
@@ -17,7 +17,8 @@
 
 /*
  * The type of 'var' is not compatible with any of the types from the
- * generic-association.  This is a compile-time error.
+ * generic-association.  This is a constraint violation that the compiler must
+ * detect, therefore lint doesn't repeat that diagnostic.
  */
 const char *
 classify_type_without_default(double var)
@@ -29,7 +30,7 @@ classify_type_without_default(double var
 	    long long: "long long",
 	    unsigned: "unsigned"
 	);
-	/* expect-1: warning: function 'classify_type_without_default' expects to return value [214] */
+	/* expect-1: error: function 'classify_type_without_default' expects to return value [214] */
 }
 
 /*

Index: src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.21 src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.22
--- src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c:1.21	Wed Aug  2 18:51:25 2023
+++ src/tests/usr.bin/xlint/lint1/d_c99_bool_strict_syshdr.c	Sun Aug  6 19:44:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: d_c99_bool_strict_syshdr.c,v 1.21 2023/08/02 18:51:25 rillig Exp $	*/
+/*	$NetBSD: d_c99_bool_strict_syshdr.c,v 1.22 2023/08/06 19:44:50 rillig Exp $	*/
 # 3 "d_c99_bool_strict_syshdr.c"
 
 /*
@@ -168,7 +168,7 @@ _Bool
 str_equal_bad(const char *s1, const char *s2)
 {
 	/* expect+2: error: operand of '!' must be bool, not 'int' [330] */
-	/* expect+1: warning: function 'str_equal_bad' expects to return value [214] */
+	/* expect+1: error: function 'str_equal_bad' expects to return value [214] */
 	return !strcmp(s1, s2);
 }
 

Index: src/tests/usr.bin/xlint/lint1/d_fold_test.c
diff -u src/tests/usr.bin/xlint/lint1/d_fold_test.c:1.7 src/tests/usr.bin/xlint/lint1/d_fold_test.c:1.8
--- src/tests/usr.bin/xlint/lint1/d_fold_test.c:1.7	Sun Jul  9 11:18:55 2023
+++ src/tests/usr.bin/xlint/lint1/d_fold_test.c	Sun Aug  6 19:44:50 2023
@@ -81,6 +81,6 @@ void do_while_struct(struct s s)	{ do { 
 
 /* C99 6.5.15 does not require a scalar type, curiously. */
 /* expect+3: error: first operand of '?' must have scalar type [170] */
-/* expect+2: warning: function 'conditional_struct' expects to return value [214] */
+/* expect+2: error: function 'conditional_struct' expects to return value [214] */
 /* expect+1: warning: parameter 's' unused in function 'conditional_struct' [231] */
 int conditional_struct(struct s s)	{ return s ? 1 : 2; }
Index: src/tests/usr.bin/xlint/lint1/msg_126.c
diff -u src/tests/usr.bin/xlint/lint1/msg_126.c:1.7 src/tests/usr.bin/xlint/lint1/msg_126.c:1.8
--- src/tests/usr.bin/xlint/lint1/msg_126.c:1.7	Fri Jul  7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/msg_126.c	Sun Aug  6 19:44:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_126.c,v 1.7 2023/07/07 19:45:22 rillig Exp $	*/
+/*	$NetBSD: msg_126.c,v 1.8 2023/08/06 19:44:50 rillig Exp $	*/
 # 3 "msg_126.c"
 
 // Test for message: incompatible types '%s' and '%s' in conditional [126]
@@ -10,6 +10,6 @@ int
 max(int cond, void *ptr, double dbl)
 {
 	/* expect+2: error: incompatible types 'pointer to void' and 'double' in conditional [126] */
-	/* expect+1: warning: function 'max' expects to return value [214] */
+	/* expect+1: error: function 'max' expects to return value [214] */
 	return cond ? ptr : dbl;
 }
Index: src/tests/usr.bin/xlint/lint1/msg_170.c
diff -u src/tests/usr.bin/xlint/lint1/msg_170.c:1.7 src/tests/usr.bin/xlint/lint1/msg_170.c:1.8
--- src/tests/usr.bin/xlint/lint1/msg_170.c:1.7	Sun Jul  9 11:18:55 2023
+++ src/tests/usr.bin/xlint/lint1/msg_170.c	Sun Aug  6 19:44:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_170.c,v 1.7 2023/07/09 11:18:55 rillig Exp $	*/
+/*	$NetBSD: msg_170.c,v 1.8 2023/08/06 19:44:50 rillig Exp $	*/
 # 3 "msg_170.c"
 
 // Test for message: first operand of '?' must have scalar type [170]
@@ -14,6 +14,6 @@ _Bool
 example(const struct number *num)
 {
 	/* expect+2: error: first operand of '?' must have scalar type [170] */
-	/* expect+1: warning: function 'example' expects to return value [214] */
+	/* expect+1: error: function 'example' expects to return value [214] */
 	return *num ? 1 : 0;
 }

Index: src/tests/usr.bin/xlint/lint1/expr_cast.c
diff -u src/tests/usr.bin/xlint/lint1/expr_cast.c:1.4 src/tests/usr.bin/xlint/lint1/expr_cast.c:1.5
--- src/tests/usr.bin/xlint/lint1/expr_cast.c:1.4	Fri Jul  7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/expr_cast.c	Sun Aug  6 19:44:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: expr_cast.c,v 1.4 2023/07/07 19:45:22 rillig Exp $	*/
+/*	$NetBSD: expr_cast.c,v 1.5 2023/08/06 19:44:50 rillig Exp $	*/
 # 3 "expr_cast.c"
 
 /*
@@ -28,6 +28,6 @@ cast(void)
 	};
 
 	/* expect+2: error: invalid cast from 'struct S' to 'struct S' [147] */
-	/* expect+1: warning: function 'cast' expects to return value [214] */
+	/* expect+1: error: function 'cast' expects to return value [214] */
 	return (struct S)local;
 }

Index: src/tests/usr.bin/xlint/lint1/lang_level_c99.c
diff -u src/tests/usr.bin/xlint/lint1/lang_level_c99.c:1.1 src/tests/usr.bin/xlint/lint1/lang_level_c99.c:1.2
--- src/tests/usr.bin/xlint/lint1/lang_level_c99.c:1.1	Sun Aug  6 19:31:06 2023
+++ src/tests/usr.bin/xlint/lint1/lang_level_c99.c	Sun Aug  6 19:44:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: lang_level_c99.c,v 1.1 2023/08/06 19:31:06 rillig Exp $	*/
+/*	$NetBSD: lang_level_c99.c,v 1.2 2023/08/06 19:44:50 rillig Exp $	*/
 # 3 "lang_level_c99.c"
 
 /*
@@ -297,7 +297,7 @@ const const int duplicate_type_qualifier
 //
 // Irrelevant, as lint only sees the preprocessed source code.
 
-// [-] return without expression not permitted in function that returns a value
+// [x] return without expression not permitted in function that returns a value
 // (and vice versa)
 
 void
@@ -311,7 +311,6 @@ return_no_expr(int x)
 int
 return_expr(void)
 {
-	// FIXME: Make this an error in C99 and later.
-	/* expect+1: warning: function 'return_expr' expects to return value [214] */
+	/* expect+1: error: function 'return_expr' expects to return value [214] */
 	return;
 }

Index: src/tests/usr.bin/xlint/lint1/msg_109.c
diff -u src/tests/usr.bin/xlint/lint1/msg_109.c:1.6 src/tests/usr.bin/xlint/lint1/msg_109.c:1.7
--- src/tests/usr.bin/xlint/lint1/msg_109.c:1.6	Fri Jul  7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/msg_109.c	Sun Aug  6 19:44:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_109.c,v 1.6 2023/07/07 19:45:22 rillig Exp $	*/
+/*	$NetBSD: msg_109.c,v 1.7 2023/08/06 19:44:50 rillig Exp $	*/
 # 3 "msg_109.c"
 
 // Test for message: void type illegal in expression [109]
@@ -10,6 +10,6 @@ int
 example(int arg)
 {
 	/* expect+2: error: void type illegal in expression [109] */
-	/* expect+1: warning: function 'example' expects to return value [214] */
+	/* expect+1: error: function 'example' expects to return value [214] */
 	return arg + (void)4;
 }

Index: src/tests/usr.bin/xlint/lint1/msg_132.c
diff -u src/tests/usr.bin/xlint/lint1/msg_132.c:1.31 src/tests/usr.bin/xlint/lint1/msg_132.c:1.32
--- src/tests/usr.bin/xlint/lint1/msg_132.c:1.31	Sat Jun  3 20:28:54 2023
+++ src/tests/usr.bin/xlint/lint1/msg_132.c	Sun Aug  6 19:44:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_132.c,v 1.31 2023/06/03 20:28:54 rillig Exp $	*/
+/*	$NetBSD: msg_132.c,v 1.32 2023/08/06 19:44:50 rillig Exp $	*/
 # 3 "msg_132.c"
 
 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
@@ -175,7 +175,7 @@ const char *
 cover_build_plus_minus(const char *arr, double idx)
 {
 	/* expect+3: error: operands of '+' have incompatible types 'pointer to const char' and 'double' [107] */
-	/* expect+2: warning: function 'cover_build_plus_minus' expects to return value [214] */
+	/* expect+2: error: function 'cover_build_plus_minus' expects to return value [214] */
 	if (idx > 0.0)
 		return arr + idx;
 	return arr + (unsigned int)idx;

Index: src/tests/usr.bin/xlint/lint1/msg_204.c
diff -u src/tests/usr.bin/xlint/lint1/msg_204.c:1.10 src/tests/usr.bin/xlint/lint1/msg_204.c:1.11
--- src/tests/usr.bin/xlint/lint1/msg_204.c:1.10	Wed Aug  2 18:51:25 2023
+++ src/tests/usr.bin/xlint/lint1/msg_204.c	Sun Aug  6 19:44:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_204.c,v 1.10 2023/08/02 18:51:25 rillig Exp $	*/
+/*	$NetBSD: msg_204.c,v 1.11 2023/08/06 19:44:50 rillig Exp $	*/
 # 3 "msg_204.c"
 
 // Test for message: controlling expressions must have scalar type [204]
@@ -108,5 +108,5 @@ void do_while_struct(struct s s)	{ do { 
  * controlling expression must have a scalar type, curiously.
  */
 /* expect+2: error: first operand of '?' must have scalar type [170] */
-/* expect+1: warning: function 'conditional_struct' expects to return value [214] */
+/* expect+1: error: function 'conditional_struct' expects to return value [214] */
 int conditional_struct(struct s s)	{ return s ? 1 : 2; }

Index: src/tests/usr.bin/xlint/lint1/msg_214.c
diff -u src/tests/usr.bin/xlint/lint1/msg_214.c:1.5 src/tests/usr.bin/xlint/lint1/msg_214.c:1.6
--- src/tests/usr.bin/xlint/lint1/msg_214.c:1.5	Fri Jul  7 19:45:22 2023
+++ src/tests/usr.bin/xlint/lint1/msg_214.c	Sun Aug  6 19:44:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg_214.c,v 1.5 2023/07/07 19:45:22 rillig Exp $	*/
+/*	$NetBSD: msg_214.c,v 1.6 2023/08/06 19:44:50 rillig Exp $	*/
 # 3 "msg_214.c"
 
 // Test for message: function '%s' expects to return value [214]
@@ -8,6 +8,6 @@
 int
 int_function(void)
 {
-	/* expect+1: warning: function 'int_function' expects to return value [214] */
+	/* expect+1: error: function 'int_function' expects to return value [214] */
 	return;
 }

Index: src/usr.bin/xlint/lint1/func.c
diff -u src/usr.bin/xlint/lint1/func.c:1.173 src/usr.bin/xlint/lint1/func.c:1.174
--- src/usr.bin/xlint/lint1/func.c:1.173	Wed Aug  2 18:51:25 2023
+++ src/usr.bin/xlint/lint1/func.c	Sun Aug  6 19:44:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: func.c,v 1.173 2023/08/02 18:51:25 rillig Exp $	*/
+/*	$NetBSD: func.c,v 1.174 2023/08/06 19:44:50 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.173 2023/08/02 18:51:25 rillig Exp $");
+__RCSID("$NetBSD: func.c,v 1.174 2023/08/06 19:44:50 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -1052,12 +1052,13 @@ stmt_return(bool sys, tnode_t *tn)
 		error(213, funcsym->s_name);
 		expr_free_all();
 		tn = NULL;
-	} else if (tn == NULL && funcsym->s_type->t_subt->t_tspec != VOID) {
-		/*
-		 * Assume that the function has a return value only if it
-		 * is explicitly declared.
-		 */
-		if (!funcsym->s_return_type_implicit_int)
+	}
+	if (tn == NULL && funcsym->s_type->t_subt->t_tspec != VOID
+	    && !funcsym->s_return_type_implicit_int) {
+		if (allow_c99)
+			/* function '%s' expects to return value */
+			error(214, funcsym->s_name);
+		else
 			/* function '%s' expects to return value */
 			warning(214, funcsym->s_name);
 	}

Reply via email to