Re: [PATCH v2] specify void prototype for functions with no parameters
Paul Eggert <[email protected]> Tue, 30 Aug 2022 16:53:51 -0500
| Newsgroups | gmane.comp.sysutils.autoconf.patches |
|---|---|
| Message-ID | <[email protected]> |
On 8/29/22 21:35, Khem Raj wrote: > Compilers defaulting to C99 flag such functions as warning which fails > to compile when using -Werror As mentioned earlier, projects should not use -Werror when configuring, for several reasons (this is just one). After you mentioned rsync was using something like -Werror I sent in a patch to the rsync folks, and rsync has been fixed: https://github.com/WayneD/rsync/commit/9a3449a3980421f84ac55498ba565bc112b20d6c What other projects are doing it? They should be fixed too, regardless of whether we change Autoconf here. As for Autoconf, if we're going to make this change at all, we should do it fully. Something like the attached patch, perhaps. I haven't installed it.
0001-Port-to-compilers-that-moan-about-K-R-func-decls.patch
(text/x-patch, 3.8 KB)
From 5b81543769d4f59f6113bbad004465c6fb30e1f7 Mon Sep 17 00:00:00 2001 From: Paul Eggert <[email protected]> Date: Tue, 30 Aug 2022 16:34:14 -0500 Subject: [PATCH] Port to compilers that moan about K&R func decls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lib/autoconf/c.m4 (AC_LANG_CALL, AC_LANG_FUNC_LINK_TRY): Use '(int)' rather than '()' in function prototypes, as the latter provokes fatal errors in some compilers nowadays. * lib/autoconf/functions.m4 (AC_FUNC_STRTOD): * tests/semantics.at (AC_CHECK_DECLS): Don’t use () in a function decl. --- doc/autoconf.texi | 5 ++--- lib/autoconf/c.m4 | 19 +++++-------------- lib/autoconf/functions.m4 | 3 --- tests/semantics.at | 2 +- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 67f31064..4f4ec741 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -5460,9 +5460,8 @@ the @samp{#undef malloc}): #include <config.h> #undef malloc -#include <sys/types.h> - -void *malloc (); +#include <stdlib.h> +#undef malloc /* Allocate an N-byte block of memory from the heap. If N is zero, allocate a 1-byte block. */ diff --git a/lib/autoconf/c.m4 b/lib/autoconf/c.m4 index abbb83fe..ca166557 100644 --- a/lib/autoconf/c.m4 +++ b/lib/autoconf/c.m4 @@ -126,14 +126,8 @@ m4_define([AC_LANG_CALL(C)], m4_if([$2], [main], , [/* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC - builtin and then its argument prototype would still apply. - The 'extern "C"' is for builds by C++ compilers; - although this is not generally supported in C code, supporting it here - has little cost and some practical benefit (sr 110532). */ -#ifdef __cplusplus -extern "C" -#endif -char $2 ();])], [return $2 ();])]) + builtin and then its argument prototype would still apply. */ +char $2 (int);])], [return $2 (0);])]) # AC_LANG_FUNC_LINK_TRY(C)(FUNCTION) @@ -157,7 +151,7 @@ m4_define([AC_LANG_FUNC_LINK_TRY(C)], #define $1 innocuous_$1 /* System header to define __stub macros and hopefully few prototypes, - which can conflict with char $1 (); below. */ + which can conflict with char $1 (int); below. */ #include <limits.h> #undef $1 @@ -165,17 +159,14 @@ m4_define([AC_LANG_FUNC_LINK_TRY(C)], /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC builtin and then its argument prototype would still apply. */ -#ifdef __cplusplus -extern "C" -#endif -char $1 (); +char $1 (int); /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ #if defined __stub_$1 || defined __stub___$1 choke me #endif -], [return $1 ();])]) +], [return $1 (0);])]) # AC_LANG_BOOL_COMPILE_TRY(C)(PROLOGUE, EXPRESSION) diff --git a/lib/autoconf/functions.m4 b/lib/autoconf/functions.m4 index 9f44a1ce..ee519a38 100644 --- a/lib/autoconf/functions.m4 +++ b/lib/autoconf/functions.m4 @@ -1613,9 +1613,6 @@ AC_DEFUN([AC_FUNC_STRTOD], AC_CACHE_CHECK(for working strtod, ac_cv_func_strtod, [AC_RUN_IFELSE([AC_LANG_SOURCE([[ ]AC_INCLUDES_DEFAULT[ -#ifndef strtod -double strtod (); -#endif int main (void) { diff --git a/tests/semantics.at b/tests/semantics.at index d24c4551..276d9744 100644 --- a/tests/semantics.at +++ b/tests/semantics.at @@ -207,7 +207,7 @@ AT_CHECK_MACRO([AC_CHECK_DECLS], [[extern int yes; enum { myenum }; extern struct mystruct_s { int x[20]; } mystruct; - extern int myfunc(); + extern int myfunc (int); #define mymacro1(arg) arg #define mymacro2]]) # Ensure we can detect missing declarations of functions whose -- 2.37.2