build: fix compiling with GCC 4.x versions
- silence false positive picky warnings. - avoid "possible noreturn" warnings for standalone tests and examples. - fix to compile without `#pragma GCC diagnostic push` support. - fix "#pragma GCC diagnostic not allowed inside functions". Prerequisite for #15975 that needs GCC 4.4 for the latest pre-built CeGCC/mingw32ce toolchain for Windows CE. Cherry-picked from #15975 Closes #16062
This commit is contained in:
parent
96843f4ef7
commit
7e814c8717
@ -236,6 +236,24 @@ if(PICKY_COMPILER)
|
||||
list(APPEND _picky "${_ccopt}")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
if(CMAKE_C_COMPILER_VERSION VERSION_LESS 4.5)
|
||||
# Avoid false positives
|
||||
list(APPEND _picky "-Wno-shadow")
|
||||
list(APPEND _picky "-Wno-unreachable-code")
|
||||
endif()
|
||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.2 AND CMAKE_C_COMPILER_VERSION VERSION_LESS 4.6)
|
||||
# GCC <4.6 do not support #pragma to suppress warnings locally. Disable them globally instead.
|
||||
list(APPEND _picky "-Wno-overlength-strings")
|
||||
endif()
|
||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.0 AND CMAKE_C_COMPILER_VERSION VERSION_LESS 4.7)
|
||||
list(APPEND _picky "-Wno-missing-field-initializers") # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36750
|
||||
endif()
|
||||
if(NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.3 AND CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8)
|
||||
list(APPEND _picky "-Wno-type-limits") # Avoid false positives
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
@ -31,6 +31,10 @@
|
||||
#include <curl/curl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic ignored "-Woverlength-strings"
|
||||
#endif
|
||||
|
||||
static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||
{
|
||||
fwrite(ptr, size, nmemb, (FILE *)stream);
|
||||
@ -41,11 +45,6 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm)
|
||||
{
|
||||
CURLcode rv = CURLE_ABORTED_BY_CALLBACK;
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Woverlength-strings"
|
||||
#endif
|
||||
|
||||
/** This example uses two (fake) certificates **/
|
||||
static const char mypem[] =
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
@ -90,10 +89,6 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm)
|
||||
"Z05phkOTOPu220+DkdRgfks+KzgHVZhepA==\n"
|
||||
"-----END CERTIFICATE-----\n";
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
BIO *cbio = BIO_new_mem_buf(mypem, sizeof(mypem));
|
||||
X509_STORE *cts = SSL_CTX_get_cert_store((SSL_CTX *)sslctx);
|
||||
int i;
|
||||
|
||||
@ -30,6 +30,19 @@
|
||||
#include <string.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
/* Avoid warning in FD_SET() with pre-2020 Cygwin/MSYS releases:
|
||||
* warning: conversion to 'long unsigned int' from 'curl_socket_t' {aka 'int'}
|
||||
* may change the sign of the result [-Wsign-conversion]
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#ifdef __DJGPP__
|
||||
#pragma GCC diagnostic ignored "-Warith-conversion"
|
||||
#endif
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma warning(disable:4127) /* conditional expression is constant */
|
||||
#endif
|
||||
|
||||
/* Auxiliary function that waits on the socket. */
|
||||
static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
|
||||
{
|
||||
@ -49,20 +62,6 @@ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
|
||||
FD_ZERO(&outfd);
|
||||
FD_ZERO(&errfd);
|
||||
|
||||
/* Avoid this warning with pre-2020 Cygwin/MSYS releases:
|
||||
* warning: conversion to 'long unsigned int' from 'curl_socket_t' {aka 'int'}
|
||||
* may change the sign of the result [-Wsign-conversion]
|
||||
*/
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#if defined(__DJGPP__)
|
||||
#pragma GCC diagnostic ignored "-Warith-conversion"
|
||||
#endif
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4127) /* conditional expression is constant */
|
||||
#endif
|
||||
FD_SET(sockfd, &errfd); /* always check for error */
|
||||
|
||||
if(for_recv) {
|
||||
@ -71,11 +70,6 @@ static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
|
||||
else {
|
||||
FD_SET(sockfd, &outfd);
|
||||
}
|
||||
#if defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
/* select() returns the number of signalled sockets or -1 */
|
||||
res = select((int)sockfd + 1, &infd, &outfd, &errfd, &tv);
|
||||
|
||||
@ -41,6 +41,10 @@
|
||||
#include <curl/curl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic ignored "-Woverlength-strings"
|
||||
#endif
|
||||
|
||||
static size_t writefunction(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||
{
|
||||
fwrite(ptr, size, nmemb, stream);
|
||||
@ -55,11 +59,6 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm)
|
||||
RSA *rsa = NULL;
|
||||
int ret;
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Woverlength-strings"
|
||||
#endif
|
||||
|
||||
const char *mypem = /* www.cacert.org */
|
||||
"-----BEGIN CERTIFICATE-----\n"\
|
||||
"MIIHPTCCBSWgAwIBAgIBADANBgkqhkiG9w0BAQQFADB5MRAwDgYDVQQKEwdSb290\n"\
|
||||
@ -124,10 +123,6 @@ static CURLcode sslctx_function(CURL *curl, void *sslctx, void *parm)
|
||||
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"\
|
||||
"-----END RSA PRIVATE KEY-----\n";
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
(void)curl; /* avoid warnings */
|
||||
(void)parm; /* avoid warnings */
|
||||
|
||||
|
||||
@ -1113,6 +1113,23 @@ AC_DEFUN([CURL_SET_COMPILER_WARNING_OPTS], [
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if test "$compiler_num" -lt "405"; then
|
||||
dnl Avoid false positives
|
||||
tmp_CFLAGS="$tmp_CFLAGS -Wno-shadow"
|
||||
tmp_CFLAGS="$tmp_CFLAGS -Wno-unreachable-code"
|
||||
fi
|
||||
if test "$compiler_num" -ge "402" -a "$compiler_num" -lt "406"; then
|
||||
dnl GCC <4.6 do not support #pragma to suppress warnings locally. Disable globally instead.
|
||||
tmp_CFLAGS="$tmp_CFLAGS -Wno-overlength-strings"
|
||||
fi
|
||||
if test "$compiler_num" -ge "400" -a "$compiler_num" -lt "407"; then
|
||||
dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84685
|
||||
tmp_CFLAGS="$tmp_CFLAGS -Wno-missing-field-initializers"
|
||||
fi
|
||||
if test "$compiler_num" -ge "403" -a "$compiler_num" -lt "408"; then
|
||||
dnl Avoid false positives
|
||||
tmp_CFLAGS="$tmp_CFLAGS -Wno-type-limits"
|
||||
fi
|
||||
;;
|
||||
#
|
||||
HP_UX_C)
|
||||
|
||||
@ -140,11 +140,11 @@ static int debug_cb(CURL *handle, curl_infotype type,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int err(void)
|
||||
{
|
||||
fprintf(stderr, "something unexpected went wrong - bailing out!\n");
|
||||
exit(2);
|
||||
}
|
||||
#define ERR() \
|
||||
do { \
|
||||
fprintf(stderr, "something unexpected went wrong - bailing out!\n"); \
|
||||
exit(2); \
|
||||
} while(0)
|
||||
|
||||
static void usage(const char *msg)
|
||||
{
|
||||
@ -292,24 +292,24 @@ int main(int argc, char *argv[])
|
||||
curl_easy_setopt(handles[i].h, CURLOPT_RESOLVE, resolve) != CURLE_OK ||
|
||||
curl_easy_setopt(handles[i].h, CURLOPT_PIPEWAIT, 1L) ||
|
||||
curl_easy_setopt(handles[i].h, CURLOPT_URL, url) != CURLE_OK) {
|
||||
err();
|
||||
ERR();
|
||||
}
|
||||
curl_easy_setopt(handles[i].h, CURLOPT_HTTP_VERSION, (long)http_version);
|
||||
}
|
||||
|
||||
multi_handle = curl_multi_init();
|
||||
if(!multi_handle)
|
||||
err();
|
||||
ERR();
|
||||
|
||||
for(i = 0; i < HANDLECOUNT; i++) {
|
||||
if(curl_multi_add_handle(multi_handle, handles[i].h) != CURLM_OK)
|
||||
err();
|
||||
ERR();
|
||||
}
|
||||
|
||||
for(rounds = 0;; rounds++) {
|
||||
fprintf(stderr, "INFO: multi_perform round %d\n", rounds);
|
||||
if(curl_multi_perform(multi_handle, &still_running) != CURLM_OK)
|
||||
err();
|
||||
ERR();
|
||||
|
||||
if(!still_running) {
|
||||
int as_expected = 1;
|
||||
@ -343,7 +343,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if(curl_multi_poll(multi_handle, NULL, 0, 100, &numfds) != CURLM_OK)
|
||||
err();
|
||||
ERR();
|
||||
|
||||
/* !checksrc! disable EQUALSNULL 1 */
|
||||
while((msg = curl_multi_info_read(multi_handle, &msgs_left)) != NULL) {
|
||||
|
||||
@ -180,11 +180,11 @@ static int progress_callback(void *clientp,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int err(void)
|
||||
{
|
||||
fprintf(stderr, "something unexpected went wrong - bailing out!\n");
|
||||
exit(2);
|
||||
}
|
||||
#define ERR() \
|
||||
do { \
|
||||
fprintf(stderr, "something unexpected went wrong - bailing out!\n"); \
|
||||
exit(2); \
|
||||
} while(0)
|
||||
|
||||
static void usage(const char *msg)
|
||||
{
|
||||
@ -294,7 +294,7 @@ int main(int argc, char *argv[])
|
||||
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, debug_cb)
|
||||
!= CURLE_OK ||
|
||||
curl_easy_setopt(curl, CURLOPT_RESOLVE, resolve) != CURLE_OK)
|
||||
err();
|
||||
ERR();
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, http_version);
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
|
||||
#include "memdebug.h"
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#pragma GCC diagnostic ignored "-Wformat-extra-args"
|
||||
@ -1601,6 +1601,6 @@ CURLcode test(char *URL)
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
@ -44,6 +44,13 @@
|
||||
|
||||
#include "curl_printf.h"
|
||||
|
||||
/* GCC <4.6 does not support '#pragma GCC diagnostic push' and
|
||||
does not support 'pragma GCC diagnostic' inside functions. */
|
||||
#if (defined(__GNUC__) && \
|
||||
((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))))
|
||||
#define CURL_GNUC_DIAG
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define sleep(sec) Sleep((sec)*1000)
|
||||
#endif
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
***************************************************************************/
|
||||
#include "curlcheck.h"
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#endif
|
||||
@ -186,6 +186,6 @@ fail_unless(rc == 128, "return code should be 128");
|
||||
|
||||
UNITTEST_STOP
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
@ -92,7 +92,7 @@ static int verify(const char *info, const char *two)
|
||||
|
||||
UNITTEST_START
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) && !defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#pragma GCC diagnostic ignored "-Wformat-zero-length"
|
||||
@ -146,7 +146,7 @@ Curl_infof(testdata, "%s", input);
|
||||
fail_unless(strlen(output) == 2051, "Truncation of infof input 3");
|
||||
fail_unless(output[sizeof(output) - 1] == '\0', "Truncation of infof input 3");
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) && !defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ struct set {
|
||||
UNITTEST_START
|
||||
#ifdef USE_SSH
|
||||
{
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Woverlength-strings"
|
||||
#endif
|
||||
@ -78,7 +78,7 @@ UNITTEST_START
|
||||
{ NULL, NULL, NULL, NULL, CURLE_OK }
|
||||
};
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
|
||||
#pragma GCC diagnostic warning "-Woverlength-strings"
|
||||
#endif
|
||||
|
||||
@ -114,7 +114,7 @@ UNITTEST_START
|
||||
|
||||
free((void *)list[0].cp);
|
||||
}
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ static CURLcode unit_stop(void)
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Woverlength-strings"
|
||||
#endif
|
||||
@ -80,7 +80,7 @@ static const char *filecontents[] = {
|
||||
"LINE1\x1aTEST"
|
||||
};
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
|
||||
#pragma GCC diagnostic warning "-Woverlength-strings"
|
||||
#endif
|
||||
|
||||
@ -175,7 +175,7 @@ UNITTEST_START
|
||||
return (CURLcode)rc;
|
||||
UNITTEST_STOP
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user