- 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
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()
#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);
{
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"
"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;
#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)
{
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) {
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);
#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);
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"\
"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 */
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)
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)
{
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;
}
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) {
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)
{
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);
#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"
return CURLE_OK;
}
-#if defined(__GNUC__) || defined(__clang__)
+#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
#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
***************************************************************************/
#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
UNITTEST_STOP
-#if defined(__GNUC__) || defined(__clang__)
+#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
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"
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
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
{ 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
free((void *)list[0].cp);
}
-#if defined(__GNUC__) || defined(__clang__)
+#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
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
"LINE1\x1aTEST"
};
-#if defined(__GNUC__) || defined(__clang__)
+#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic warning "-Woverlength-strings"
#endif
return (CURLcode)rc;
UNITTEST_STOP
-#if defined(__GNUC__) || defined(__clang__)
+#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic pop
#endif