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;
]])