gcc: guard `#pragma diagnostic` in core code for <4.6, disable picky warnings
No binary (build failed)
—
(log yok)
| @@ -60,7 +60,9 @@ elseif(BORLAND) | |
| endif() | |
| if(PICKY_COMPILER) | |
| - | if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") |
| + | # Leave disabled for GCC <4.6, because they lack #pragma features to silence locally. |
| + | if((CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.6) OR |
| + | CMAKE_C_COMPILER_ID MATCHES "Clang") |
| # https://clang.llvm.org/docs/DiagnosticsReference.html | |
| # https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html | |
| @@ -378,15 +380,6 @@ if(PICKY_COMPILER) | |
| endforeach() | |
| if(CMAKE_C_COMPILER_ID STREQUAL "GNU") | |
| - | 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(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 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(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 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() | |
| @@ -34,7 +34,7 @@ | |
| * warning: conversion to 'long unsigned int' from 'curl_socket_t' {aka 'int'} | |
| * may change the sign of the result [-Wsign-conversion] | |
| */ | |
| - | #ifdef __GNUC__ |
| + | #ifdef __GNUC__ /* keep outside functions and without push/pop for GCC <4.6 */ |
| #pragma GCC diagnostic ignored "-Wsign-conversion" | |
| #elif defined(_MSC_VER) | |
| #pragma warning(disable:4127) /* conditional expression is constant */ | |
| @@ -31,13 +31,13 @@ | |
| #endif | |
| #ifdef HAVE_BROTLI | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| /* Ignore -Wvla warnings in brotli headers */ | |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wvla" | |
| #endif | |
| #include <brotli/decode.h> | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |
| #endif | |
| @@ -55,7 +55,7 @@ | |
| #define CURL_ALIGN8 | |
| #endif | |
| - | #if defined(__GNUC__) && defined(__APPLE__) |
| + | #if defined(CURL_HAVE_DIAG) && defined(__APPLE__) |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
| #endif | |
| @@ -441,7 +441,7 @@ void Curl_gss_log_error(struct Curl_easy *data, const char *prefix, | |
| } | |
| #endif /* CURLVERBOSE */ | |
| - | #if defined(__GNUC__) && defined(__APPLE__) |
| + | #if defined(CURL_HAVE_DIAG) && defined(__APPLE__) |
| #pragma GCC diagnostic pop | |
| #endif | |
| @@ -774,6 +774,16 @@ | |
| #define USE_SSH | |
| #endif | |
| + | /* GCC <4.6 does not support '#pragma GCC diagnostic push' and does not support |
| + | 'pragma GCC diagnostic' inside functions. |
| + | Use CURL_HAVE_DIAG to guard the above in the curl codebase, instead of |
| + | defined(__GNUC__) || defined(__clang__). |
| + | */ |
| + | #if defined(__clang__) || (defined(__GNUC__) && \ |
| + | ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)))) |
| + | #define CURL_HAVE_DIAG |
| + | #endif |
| + | |
| /* | |
| * Provide a mechanism to silence picky compilers, such as gcc 4.6+. | |
| * Parameters should of course normally not be unused, but for example when | |
| @@ -34,13 +34,13 @@ void curlx_win32_snprintf(char *buf, size_t maxlen, const char *fmt, ...) | |
| if(!maxlen) | |
| return; | |
| va_start(ap, fmt); | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wformat-nonliteral" | |
| #endif | |
| /* !checksrc! disable BANNEDFUNC 1 */ | |
| (void)vsnprintf(buf, maxlen, fmt, ap); | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |
| buf[maxlen - 1] = 0; | |
| @@ -2567,7 +2567,7 @@ static CURLcode ftp_state_mdtm_resp(struct Curl_easy *data, | |
| /* If we asked for a time of the file and we actually got one as well, | |
| we "emulate" an HTTP-style header in our output. */ | |
| - | #if defined(__GNUC__) && (defined(__DJGPP__) || defined(__AMIGA__)) |
| + | #if defined(CURL_HAVE_DIAG) && (defined(__DJGPP__) || defined(__AMIGA__)) |
| #pragma GCC diagnostic push | |
| /* 'time_t' is unsigned in MSDOS and AmigaOS. Silence: | |
| warning: comparison of unsigned expression in '>= 0' is always true */ | |
| @@ -2575,7 +2575,7 @@ static CURLcode ftp_state_mdtm_resp(struct Curl_easy *data, | |
| #endif | |
| if(data->req.no_body && ftpc->file && | |
| data->set.get_filetime && showtime) { | |
| - | #if defined(__GNUC__) && (defined(__DJGPP__) || defined(__AMIGA__)) |
| + | #if defined(CURL_HAVE_DIAG) && (defined(__DJGPP__) || defined(__AMIGA__)) |
| #pragma GCC diagnostic pop | |
| #endif | |
| char headerbuf[128]; | |
| @@ -210,13 +210,13 @@ if2ip_result_t Curl_if2ip(int af, | |
| memcpy(req.ifr_name, interf, len + 1); | |
| req.ifr_addr.sa_family = AF_INET; | |
| - | #if defined(__GNUC__) && defined(_AIX) |
| + | #if defined(CURL_HAVE_DIAG) && defined(_AIX) |
| /* Suppress warning inside system headers */ | |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wshift-sign-overflow" | |
| #endif | |
| if(ioctl(dummy, SIOCGIFADDR, &req) < 0) { | |
| - | #if defined(__GNUC__) && defined(_AIX) |
| + | #if defined(CURL_HAVE_DIAG) && defined(_AIX) |
| #pragma GCC diagnostic pop | |
| #endif | |
| sclose(dummy); | |
| @@ -27,7 +27,7 @@ | |
| #if !defined(CURL_DISABLE_LDAP) && !defined(USE_OPENLDAP) | |
| - | #if defined(__GNUC__) && defined(__APPLE__) |
| + | #if defined(CURL_HAVE_DIAG) && defined(__APPLE__) |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
| #endif | |
| @@ -994,7 +994,7 @@ const struct Curl_protocol Curl_protocol_ldap = { | |
| ZERO_NULL, /* follow */ | |
| }; | |
| - | #if defined(__GNUC__) && defined(__APPLE__) |
| + | #if defined(CURL_HAVE_DIAG) && defined(__APPLE__) |
| #pragma GCC diagnostic pop | |
| #endif | |
| @@ -672,7 +672,7 @@ static bool out_double(void *userp, | |
| /* NOTE NOTE NOTE!! Not all sprintf implementations return number of | |
| output characters */ | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wformat-nonliteral" | |
| #endif | |
| @@ -687,7 +687,7 @@ static bool out_double(void *userp, | |
| /* float and double outputs do not work without snprintf support */ | |
| work[0] = 0; | |
| #endif | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |
| DEBUGASSERT(strlen(work) < BUFFSIZE); | |
| @@ -35,7 +35,7 @@ | |
| #include "socks.h" | |
| #include "curlx/strdup.h" | |
| - | #if defined(__GNUC__) && defined(__APPLE__) |
| + | #if defined(CURL_HAVE_DIAG) && defined(__APPLE__) |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
| #endif | |
| @@ -526,7 +526,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(struct Curl_cfilter *cf, | |
| return CURLE_OK; | |
| } | |
| - | #if defined(__GNUC__) && defined(__APPLE__) |
| + | #if defined(CURL_HAVE_DIAG) && defined(__APPLE__) |
| #pragma GCC diagnostic pop | |
| #endif | |
| @@ -33,7 +33,7 @@ | |
| #include "curl_gssapi.h" | |
| #include "curl_trc.h" | |
| - | #if defined(__GNUC__) && defined(__APPLE__) |
| + | #if defined(CURL_HAVE_DIAG) && defined(__APPLE__) |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
| #endif | |
| @@ -320,7 +320,7 @@ void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5) | |
| } | |
| } | |
| - | #if defined(__GNUC__) && defined(__APPLE__) |
| + | #if defined(CURL_HAVE_DIAG) && defined(__APPLE__) |
| #pragma GCC diagnostic pop | |
| #endif | |
| @@ -32,7 +32,7 @@ | |
| #include "curl_gssapi.h" | |
| #include "curl_trc.h" | |
| - | #if defined(__GNUC__) && defined(__APPLE__) |
| + | #if defined(CURL_HAVE_DIAG) && defined(__APPLE__) |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
| #endif | |
| @@ -288,7 +288,7 @@ void Curl_auth_cleanup_spnego(struct negotiatedata *nego) | |
| nego->havemultiplerequests = FALSE; | |
| } | |
| - | #if defined(__GNUC__) && defined(__APPLE__) |
| + | #if defined(CURL_HAVE_DIAG) && defined(__APPLE__) |
| #pragma GCC diagnostic pop | |
| #endif | |
| @@ -56,13 +56,13 @@ | |
| #endif | |
| #ifdef HAVE_BROTLI | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| /* Ignore -Wvla warnings in brotli headers */ | |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wvla" | |
| #endif | |
| #include <brotli/decode.h> | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |
| #endif | |
| @@ -974,7 +974,8 @@ AC_DEFUN([CURL_SET_COMPILER_WARNING_OPTS], [ | |
| # | |
| GNU_C) | |
| # | |
| - | if test "$want_warnings" = "yes"; then |
| + | dnl Leave disabled for GCC <4.6, because they lack #pragma features to silence locally. |
| + | if test "$want_warnings" = "yes" && test "$compiler_num" -ge "406"; then |
| # | |
| dnl Do not enable -pedantic when cross-compiling with a gcc older | |
| dnl than 3.0, to avoid warnings from third party system headers. | |
| @@ -1190,15 +1191,6 @@ 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" && test "$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" && test "$compiler_num" -lt "407"; then | |
| dnl https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84685 | |
| tmp_CFLAGS="$tmp_CFLAGS -Wno-missing-field-initializers" | |
| @@ -200,12 +200,12 @@ int tool_progress_cb(void *clientp, | |
| memset(line, '#', num); | |
| line[num] = '\0'; | |
| curl_msnprintf(format, sizeof(format), "\r%%-%ds %%5.1f%%%%", barwidth); | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wformat-nonliteral" | |
| #endif | |
| curl_mfprintf(bar->out, format, line, percent); | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |
| } | |
| @@ -132,7 +132,7 @@ static void memory_tracking_init(void) | |
| ** curl tool main function. | |
| */ | |
| #ifdef _UNICODE | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| /* GCC does not know about wmain() */ | |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wmissing-prototypes" | |
| @@ -205,7 +205,7 @@ int main(int argc, char *argv[]) | |
| } | |
| #ifdef _UNICODE | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |
| #endif | |
| @@ -580,14 +580,14 @@ static const char *outtime(const char *ptr, /* %time{ ... */ | |
| if(!result) { | |
| struct tm utc; | |
| result = curlx_gmtime(secs, &utc); | |
| - | #ifdef __GNUC__ /* includes llvm/clang, but not affected as of v22.1.0 */ |
| + | #ifdef CURL_HAVE_DIAG /* includes llvm/clang, but not affected as of v22.1.0 */ |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wformat-nonliteral" | |
| #endif | |
| if(curlx_dyn_len(&format) && !result && | |
| strftime(output, sizeof(output), curlx_dyn_ptr(&format), &utc)) | |
| fputs(output, stream); | |
| - | #ifdef __GNUC__ |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |
| curlx_dyn_free(&format); | |
| @@ -58,13 +58,6 @@ extern int unitfail; /* for unittests */ | |
| #include <sys/select.h> | |
| #endif | |
| - | /* 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 |
| - | |
| #define test_setopt(A, B, C) \ | |
| do { \ | |
| result = curl_easy_setopt(A, B, C); \ | |
| @@ -33,7 +33,7 @@ | |
| # include <locale.h> /* for setlocale() */ | |
| #endif | |
| - | #if defined(CURL_GNUC_DIAG) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wformat" | |
| #pragma GCC diagnostic ignored "-Wformat-extra-args" | |
| @@ -1542,6 +1542,6 @@ static CURLcode test_lib557(const char *URL) | |
| return CURLE_OK; | |
| } | |
| - | #if defined(CURL_GNUC_DIAG) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |
| @@ -85,12 +85,12 @@ void logmsg(const char *msg, ...) | |
| va_start(ap, msg); | |
| /* Suppress for builds where CURL_PRINTF() is not set */ | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wformat-nonliteral" | |
| #endif | |
| vsnprintf(buffer, sizeof(buffer), msg, ap); | |
| - | #if defined(__GNUC__) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |
| va_end(ap); | |
| @@ -23,7 +23,7 @@ | |
| ***************************************************************************/ | |
| #include "unitcheck.h" | |
| - | #if defined(CURL_GNUC_DIAG) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wformat" | |
| #endif | |
| @@ -195,6 +195,6 @@ static CURLcode test_unit1398(const char *arg) | |
| UNITTEST_END_SIMPLE | |
| } | |
| - | #if defined(CURL_GNUC_DIAG) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |
| @@ -88,7 +88,7 @@ static CURLcode test_unit1652(const char *arg) | |
| UNITTEST_BEGIN(t1652_setup(&easy)) | |
| - | #ifdef CURL_GNUC_DIAG |
| + | #if defined(CURL_HAVE_DIAG) && !defined(__clang__) |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Wformat" /* for GCC v5 to v8 */ | |
| #pragma GCC diagnostic ignored "-Wformat-zero-length" | |
| @@ -157,7 +157,7 @@ static CURLcode test_unit1652(const char *arg) | |
| fail_unless(output[sizeof(output) - 1] == '\0', | |
| "Truncation of infof input 3"); | |
| - | #ifdef CURL_GNUC_DIAG |
| + | #if defined(CURL_HAVE_DIAG) && !defined(__clang__) |
| #pragma GCC diagnostic pop | |
| #endif | |
| @@ -38,7 +38,7 @@ static CURLcode test_unit2604(const char *arg) | |
| CURLcode result; | |
| }; | |
| - | #if defined(CURL_GNUC_DIAG) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Woverlength-strings" | |
| #endif | |
| @@ -74,7 +74,7 @@ static CURLcode test_unit2604(const char *arg) | |
| { NULL, NULL, NULL, NULL, CURLE_OK } | |
| }; | |
| - | #if defined(CURL_GNUC_DIAG) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |
| @@ -31,7 +31,7 @@ static CURLcode test_unit3200(const char *arg) | |
| #if !defined(CURL_DISABLE_COOKIES) || !defined(CURL_DISABLE_ALTSVC) || \ | |
| !defined(CURL_DISABLE_HSTS) || !defined(CURL_DISABLE_NETRC) | |
| - | #if defined(CURL_GNUC_DIAG) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic push | |
| #pragma GCC diagnostic ignored "-Woverlength-strings" | |
| #endif | |
| @@ -70,7 +70,7 @@ static CURLcode test_unit3200(const char *arg) | |
| "LINE1\x1aTEST" | |
| }; | |
| - | #if defined(CURL_GNUC_DIAG) || defined(__clang__) |
| + | #ifdef CURL_HAVE_DIAG |
| #pragma GCC diagnostic pop | |
| #endif | |