build: fix compiler warnings in feature detections

Fix or silence compiler warnings happening in feature detections
to reduce log noise. Warnings may also get promoted to errors in certain
cases, causing missed detections.

It reduces the number of warnings by 4500+ across the linux, linux-old,
macos, non-native and windows GHA workflows (~142 jobs).

Also move picky warning logic for MSVC/Borland to
`CMake/PickyWarnings.cmake. To make them listed in the picky-warnings
log output, and to also apply to feature detections to make them compile
under the same conditions as source code. The hope is to help catching
issues faster. It also improves code quality of feature tests.

Fixed/silenced:
```
warning #177: variable "dummy" was declared but never referenced
warning #177: variable "flag" was declared but never referenced
warning #177: variable "res" was declared but never referenced
warning #592: variable "s" is used before its value is set
warning #1011: missing return statement at end of non-void function "main"
warning #1786: function "SSL_CTX_set_srp_password" (declared at line 1888 of "/usr/include/openssl/ssl.h") was declared deprecated ("Since OpenSSL 3.0")
warning #1786: function "SSL_CTX_set_srp_username" (declared at line 1887 of "/usr/include/openssl/ssl.h") was declared deprecated ("Since OpenSSL 3.0")
warning #2332: a value of type "const char *" cannot be assigned to an entity of type "char *" (dropping qualifiers)
warning: 'SSL_CTX_set_srp_password' is deprecated [-Wdeprecated-declarations]
warning: 'SSL_CTX_set_srp_password' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
warning: 'SSL_CTX_set_srp_username' is deprecated [-Wdeprecated-declarations]
warning: 'SSL_CTX_set_srp_username' is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
warning: 'b' is used uninitialized [-Wuninitialized]
warning: 'gethostname' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes]
warning: Undefined or garbage value returned to caller [core.uninitialized.UndefReturn]
warning: Value stored to 'i' is never read [deadcode.DeadStores]
warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
warning: control reaches end of non-void function [-Wreturn-type]
warning: empty expression statement has no effect; remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
warning: excess elements in struct initializer
warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
warning: macro "_FILE_OFFSET_BITS" is not used [-Wunused-macros]
warning: macro "_REENTRANT" is not used [-Wunused-macros]
warning: missing braces around initializer [-Wmissing-braces]
warning: no previous extern declaration for non-static variable 'off_t_is_large' [-Wmissing-variable-declarations]
warning: no previous prototype for 'check' [-Wmissing-prototypes]
warning: no previous prototype for function 'check' [-Wmissing-prototypes]
warning: null argument where non-null required (argument 2) [-Wnonnull]
warning: passing 'const char[1]' to parameter of type 'char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
warning: passing argument 2 of 'SSL_CTX_set_srp_password' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
warning: passing argument 2 of 'SSL_CTX_set_srp_username' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
warning: unused parameter 'c' [-Wunused-parameter]
warning: unused parameter 'f' [-Wunused-parameter]
warning: unused variable 'data' [-Wunused-variable]
warning: unused variable 'dummy' [-Wunused-variable]
warning: unused variable 'flag' [-Wunused-variable]
warning: unused variable 'res' [-Wunused-variable]
warning: unused variable 's' [-Wunused-variable]
warning: variable 's' set but not used [-Wunused-but-set-variable]
warning: variable 'ts' set but not used [-Wunused-but-set-variable]
```

Closes #16287
This commit is contained in:
Viktor Szakats 2025-02-11 02:46:29 +01:00
parent ebbf51e191
commit ca2f49ded0
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
12 changed files with 164 additions and 137 deletions

View file

@ -1310,9 +1310,10 @@ AC_DEFUN([CURL_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE], [
AC_MSG_CHECKING([if compiler halts on negative sized arrays])
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
typedef char bad_t[sizeof(char) == sizeof(int) ? -1 : -1 ];
typedef char bad_t[sizeof(char) == sizeof(int) ? -1 : -1];
]],[[
bad_t dummy;
(void)dummy;
]])
],[
AC_MSG_RESULT([no])
@ -1342,11 +1343,13 @@ AC_DEFUN([CURL_CHECK_COMPILER_STRUCT_MEMBER_SIZE], [
struct mystruct *next;
};
struct mystruct myfunc();
typedef char good_t1[sizeof(myfunc().mi) == sizeof(int) ? 1 : -1 ];
typedef char good_t2[sizeof(myfunc().mc) == sizeof(char) ? 1 : -1 ];
typedef char good_t1[sizeof(myfunc().mi) == sizeof(int) ? 1 : -1];
typedef char good_t2[sizeof(myfunc().mc) == sizeof(char) ? 1 : -1];
]],[[
good_t1 dummy1;
good_t2 dummy2;
(void)dummy1;
(void)dummy2;
]])
],[
tst_compiler_check_one_works="yes"
@ -1364,11 +1367,13 @@ AC_DEFUN([CURL_CHECK_COMPILER_STRUCT_MEMBER_SIZE], [
struct mystruct *next;
};
struct mystruct myfunc();
typedef char bad_t1[sizeof(myfunc().mi) != sizeof(int) ? 1 : -1 ];
typedef char bad_t2[sizeof(myfunc().mc) != sizeof(char) ? 1 : -1 ];
typedef char bad_t1[sizeof(myfunc().mi) != sizeof(int) ? 1 : -1];
typedef char bad_t2[sizeof(myfunc().mc) != sizeof(char) ? 1 : -1];
]],[[
bad_t1 dummy1;
bad_t2 dummy2;
(void)dummy1;
(void)dummy2;
]])
],[
tst_compiler_check_two_works="no"
@ -1452,8 +1457,8 @@ AC_DEFUN([CURL_CHECK_COMPILER_SYMBOL_HIDING], [
squeeze CFLAGS
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[
$tmp_EXTERN char *dummy(char *buff);
char *dummy(char *buff)
$tmp_EXTERN const char *dummy(const char *buff);
const char *dummy(const char *buff)
{
if(buff)
return ++buff;
@ -1461,8 +1466,8 @@ AC_DEFUN([CURL_CHECK_COMPILER_SYMBOL_HIDING], [
return buff;
}
]],[[
char b[16];
char *r = dummy(&b[0]);
const char *b = "example";
const char *r = dummy(&b[0]);
if(r)
return (int)*r;
]])

View file

@ -504,11 +504,11 @@ AC_DEFUN([CURL_CHECK_LIB_ARES], [
AC_LANG_PROGRAM([[
#include <ares.h>
/* set of dummy functions in case c-ares was built with debug */
void curl_dofree() { }
void curl_sclose() { }
void curl_domalloc() { }
void curl_docalloc() { }
void curl_socket() { }
void curl_dofree(void); void curl_dofree(void) {}
void curl_sclose(void); void curl_sclose(void) {}
void curl_domalloc(void); void curl_domalloc(void) {}
void curl_docalloc(void); void curl_docalloc(void) {}
void curl_socket(void); void curl_socket(void) {}
]],[[
ares_channel channel;
ares_cancel(channel); /* added in 1.2.0 */

View file

@ -1710,7 +1710,12 @@ AC_DEFUN([CURL_CHECK_FUNC_GETHOSTNAME], [
$curl_includes_unistd
$curl_includes_bsdsocket
$curl_preprocess_callconv
extern int FUNCALLCONV gethostname($tst_arg1, $tst_arg2);
#if defined(_WIN32) && defined(WINSOCK_API_LINKAGE)
WINSOCK_API_LINKAGE
#else
extern
#endif
int FUNCALLCONV gethostname($tst_arg1, $tst_arg2);
]],[[
if(0 != gethostname(0, 0))
return 1;
@ -2140,6 +2145,7 @@ AC_DEFUN([CURL_CHECK_FUNC_GMTIME_R], [
struct tm *gmt = 0;
struct tm result;
gmt = gmtime_r(&local, &result);
(void)result;
if(gmt)
exit(0);
else
@ -2258,8 +2264,8 @@ AC_DEFUN([CURL_CHECK_FUNC_INET_NTOP], [
char ipv4res[sizeof "255.255.255.255"];
unsigned char ipv6a[26];
unsigned char ipv4a[5];
char *ipv6ptr = 0;
char *ipv4ptr = 0;
const char *ipv6ptr = 0;
const char *ipv4ptr = 0;
/* - */
ipv4res[0] = '\0';
ipv4a[0] = 0xc0;
@ -3004,7 +3010,7 @@ AC_DEFUN([CURL_CHECK_FUNC_MEMRCHR], [
AC_LANG_PROGRAM([[
$curl_includes_string
]],[[
if(0 != memrchr(0, 0, 0))
if(0 != memrchr("", 0, 0))
return 1;
]])
],[
@ -3666,7 +3672,7 @@ AC_DEFUN([CURL_CHECK_FUNC_STRCASECMP], [
AC_LANG_PROGRAM([[
$curl_includes_string
]],[[
if(0 != strcasecmp(0, 0))
if(0 != strcasecmp("", ""))
return 1;
]])
],[
@ -3965,8 +3971,10 @@ AC_DEFUN([CURL_CHECK_FUNC_STRERROR_R], [
$curl_includes_string
char *strerror_r(int errnum, char *workbuf, $arg3 bufsize);
]],[[
if(0 != strerror_r(0, 0, 0))
char s[1];
if(0 != strerror_r(0, s, 0))
return 1;
(void)s;
]])
],[
tst_glibc_strerror_r_type_arg3="$arg3"
@ -3993,7 +4001,7 @@ AC_DEFUN([CURL_CHECK_FUNC_STRERROR_R], [
AC_LANG_PROGRAM([[
$curl_includes_stdlib
$curl_includes_string
# include <errno.h>
#include <errno.h>
]],[[
char buffer[1024];
char *string = 0;
@ -4026,8 +4034,10 @@ AC_DEFUN([CURL_CHECK_FUNC_STRERROR_R], [
$curl_includes_string
int strerror_r(int errnum, char *resultbuf, $arg3 bufsize);
]],[[
if(0 != strerror_r(0, 0, 0))
char s[1];
if(0 != strerror_r(0, s, 0))
return 1;
(void)s;
]])
],[
tst_posix_strerror_r_type_arg3="$arg3"
@ -4054,7 +4064,7 @@ AC_DEFUN([CURL_CHECK_FUNC_STRERROR_R], [
AC_LANG_PROGRAM([[
$curl_includes_stdlib
$curl_includes_string
# include <errno.h>
#include <errno.h>
]],[[
char buffer[1024];
int error = 1;
@ -4266,7 +4276,7 @@ AC_DEFUN([CURL_CHECK_FUNC_STRTOK_R], [
AC_LANG_PROGRAM([[
$curl_includes_string
]],[[
if(0 != strtok_r(0, 0, 0))
if(0 != strtok_r(0, "", 0))
return 1;
]])
],[
@ -4351,7 +4361,7 @@ AC_DEFUN([CURL_CHECK_FUNC_STRTOLL], [
AC_LANG_PROGRAM([[
$curl_includes_stdlib
]],[[
if(0 != strtoll(0, 0, 0))
if(0 != strtoll("", 0, 0))
return 1;
]])
],[
@ -4463,6 +4473,7 @@ AC_DEFUN([CURL_ATOMIC],[
]],[[
_Atomic int i = 0;
i = 4; // Force an atomic-write operation.
(void)i;
]])
],[
AC_MSG_RESULT([yes])

View file

@ -46,6 +46,9 @@ if test "x$OPT_OPENSSL" != xno; then
my_ac_save_LIBS=$LIBS
LIBS="-lgdi32 $LIBS"
AC_LINK_IFELSE([ AC_LANG_PROGRAM([[
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windef.h>
#include <wingdi.h>
]],
@ -284,6 +287,7 @@ if test "x$OPT_OPENSSL" != xno; then
#include <openssl/opensslv.h>
]],[[
int dummy = LIBRESSL_VERSION_NUMBER;
(void)dummy;
]])
],[
AC_MSG_RESULT([yes])
@ -352,10 +356,13 @@ if test "$OPENSSL_ENABLED" = "1"; then
AC_MSG_CHECKING([for SRP support in OpenSSL])
AC_LINK_IFELSE([
AC_LANG_PROGRAM([[
#ifndef OPENSSL_SUPPRESS_DEPRECATED
#define OPENSSL_SUPPRESS_DEPRECATED
#endif
#include <openssl/ssl.h>
]],[[
SSL_CTX_set_srp_username(NULL, "");
SSL_CTX_set_srp_password(NULL, "");
SSL_CTX_set_srp_username(NULL, NULL);
SSL_CTX_set_srp_password(NULL, NULL);
]])
],[
AC_MSG_RESULT([yes])

View file

@ -51,8 +51,7 @@ m4_define([AC_LANG_PROGRAM(C)],
int main(void)
{
$2
;
return 0;
return 0;
}])
dnl Override Autoconf's AC_LANG_CALL (C)

View file

@ -56,7 +56,8 @@ AC_DEFUN([CURL_CHECK_NEED_REENTRANT_ERRNO], [
#include <errno.h>
]],[[
#ifdef errno
int dummy=1;
int dummy = 1;
(void)dummy;
#else
#error force compilation error
#endif
@ -70,7 +71,8 @@ AC_DEFUN([CURL_CHECK_NEED_REENTRANT_ERRNO], [
#include <errno.h>
]],[[
#ifdef errno
int dummy=1;
int dummy = 1;
(void)dummy;
#else
#error force compilation error
#endif
@ -411,7 +413,8 @@ AC_DEFUN([CURL_CONFIGURE_REENTRANT], [
AC_LANG_PROGRAM([[
]],[[
#ifdef _REENTRANT
int dummy=1;
int dummy = 1;
(void)dummy;
#else
#error force compilation error
#endif
@ -471,7 +474,8 @@ AC_DEFUN([CURL_CONFIGURE_THREAD_SAFE], [
AC_LANG_PROGRAM([[
]],[[
#ifdef _THREAD_SAFE
int dummy=1;
int dummy = 1;
(void)dummy;
#else
#error force compilation error
#endif