Skip to content

gcc: guard #pragma diagnostic in core code for <4.6, disable picky warnings - #20907

Closed
vszakats wants to merge 27 commits into
curl:masterfrom
vszakats:ancientgcc
Closed

vszakats wants to merge 27 commits into
curl:masterfrom
vszakats:ancientgcc

Conversation

@vszakats

@vszakats vszakats commented Mar 12, 2026 •

Copy link
Copy Markdown
Member

Extend #pragma diagnostic push/pop guards to the whole codebase
(from tests and examples only) to disable it for GCC <4.6. Rename guard
to CURL_HAVE_DIAG and make it include llvm/clang to be interchangeable
with __GNUC__ || __clang__ in this context.

The above means no longer disabling certain warnings locally, so pair
this with disabling all picky warnings for GCC <4.6.

Also:

  • drop global workarounds for misbehaving GCC <4.6 compiler warnings.
    Not needed with picky warnings disabled.

Reported-by: fds242 on github
Reported-by: Sergey Fedorov
Thanks-to: Orgad Shaneh
Follow-up to f07a98a #20366
Fixes #20892
Fixes #20924
Closes #20902


  • set compiler version minimums to GCC 4.8.1 (2013-03-22) and clang 3.0.0 (2011-11-29)? → future/sep PR
  • set macOS minimum to 10.7 (for built-in zlib, which reports itself as 1.2.12 (2022), but fails on compile when targeting <10.7 or iOS <5.0) → future/sep PR or maybe fix
  • rename CURL_GNUC_DIAG to CURL_HAVE_DIAG, also set for __clang__, change all uses?
  • replace remaining __GNUC__ uses with CURL_HAS_DIAG in non-portable lines? (in particular, Apple?)

@vszakats

Copy link
Copy Markdown
Member Author

My take on extending ancient GCC support. If we really want to.

@vszakats vszakats changed the title gcc: extend <4.6 workaround to core code gcc: extend <4.6 workaround to core code, disable all picky warnings Mar 12, 2026
@vszakats vszakats changed the title gcc: extend <4.6 workaround to core code, disable all picky warnings gcc: extend <4.6 workaround to core code, disable picky warnings Mar 12, 2026
@vszakats
vszakats marked this pull request as draft March 12, 2026 13:35
@vszakats
vszakats marked this pull request as ready for review March 12, 2026 18:12
@vszakats
vszakats marked this pull request as draft March 15, 2026 12:59
Comment thread CMake/PickyWarnings.cmake Resolved
@vszakats
vszakats marked this pull request as ready for review March 17, 2026 23:09
@vszakats
vszakats requested a review from Copilot March 17, 2026 23:09
@vszakats

Copy link
Copy Markdown
Member Author

augment review

@vszakats vszakats changed the title gcc: extend <4.6 workaround to core code, disable picky warnings gcc: guard off #pragma diagnostic in core code, disable picky warnings Mar 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR centralizes compiler-diagnostic support detection by introducing CURL_HAVE_DIAG and updating code to use it when guarding #pragma GCC diagnostic push/pop, while also aligning warning-flag enabling to avoid unsupported pragmas on GCC < 4.6.

Changes:

  • Add CURL_HAVE_DIAG in lib/curl_setup.h (Clang or GCC >= 4.6) and remove the older CURL_GNUC_DIAG test-only macro.
  • Replace scattered __GNUC__/__clang__/CURL_GNUC_DIAG checks with CURL_HAVE_DIAG across libcurl, tool, tests, and test servers.
  • Update Autotools and CMake picky-warning logic to keep picky warnings disabled for GCC < 4.6.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/curl_setup.h Defines CURL_HAVE_DIAG to gate diagnostic pragmas based on compiler capability.
tests/libtest/first.h Removes CURL_GNUC_DIAG now that a global capability macro exists.
tests/unit/unit3200.c Uses CURL_HAVE_DIAG around overlength-string suppression pragmas.
tests/unit/unit2604.c Uses CURL_HAVE_DIAG around overlength-string suppression pragmas.
tests/unit/unit1652.c Switches GCC-only diagnostic push/pop to CURL_HAVE_DIAG (excluding clang).
tests/unit/unit1398.c Uses CURL_HAVE_DIAG around format-warning suppression pragmas.
tests/server/util.c Uses CURL_HAVE_DIAG around nonliteral-format suppression pragmas.
tests/libtest/lib557.c Uses CURL_HAVE_DIAG around format-warning suppression pragmas.
lib/content_encoding.c Uses CURL_HAVE_DIAG when silencing warnings from brotli headers.
lib/version.c Uses CURL_HAVE_DIAG when silencing warnings from brotli headers.
lib/mprintf.c Uses CURL_HAVE_DIAG around nonliteral-format suppression pragmas.
lib/curlx/snprintf.c Uses CURL_HAVE_DIAG around nonliteral-format suppression pragmas.
src/tool_cb_prg.c Uses CURL_HAVE_DIAG around nonliteral-format suppression pragmas.
src/tool_main.c Uses CURL_HAVE_DIAG around missing-prototypes suppression pragmas for wmain.
src/tool_writeout.c Uses CURL_HAVE_DIAG around nonliteral-format suppression pragmas for strftime.
lib/ftp.c Uses CURL_HAVE_DIAG for platform-specific warning suppression blocks.
lib/if2ip.c Uses CURL_HAVE_DIAG for AIX-specific warning suppression in system headers.
lib/ldap.c Uses CURL_HAVE_DIAG for Apple-specific deprecated-declarations suppression.
lib/curl_gssapi.c Uses CURL_HAVE_DIAG for Apple-specific deprecated-declarations suppression.
lib/socks_gssapi.c Uses CURL_HAVE_DIAG for Apple-specific deprecated-declarations suppression.
lib/vauth/spnego_gssapi.c Uses CURL_HAVE_DIAG for Apple-specific deprecated-declarations suppression.
lib/vauth/krb5_gssapi.c Uses CURL_HAVE_DIAG for Apple-specific deprecated-declarations suppression.
m4/curl-compilers.m4 Avoids enabling warning options for GCC < 4.6 in Autotools warning setup.
CMake/PickyWarnings.cmake Avoids enabling picky warnings for GCC < 4.6 in CMake builds.
docs/examples/sendrecv.c Clarifies comment about keeping pragma usage compatible with GCC < 4.6.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread lib/curl_setup.h Resolved
@vszakats vszakats changed the title gcc: guard off #pragma diagnostic in core code, disable picky warnings gcc: guard #pragma diagnostic for <4.6 in core code, disable picky warnings Mar 17, 2026
@augmentcode

augmentcode Bot commented Mar 17, 2026 •

Copy link
Copy Markdown
🤖 Augment PR Summary

Summary: This PR avoids using #pragma GCC diagnostic push/pop on GCC < 4.6 by introducing a feature macro and applying it across the core curl codebase.

  • Adds CURL_HAVE_DIAG (clang or GCC ≥ 4.6) in lib/curl_setup.h and uses it to guard GCC-style diagnostic pragmas.
  • Updates libcurl, curl tool, and test sources to use CURL_HAVE_DIAG instead of ad-hoc __GNUC__/__clang__ checks.
  • Disables “picky warnings” for GCC < 4.6 in both CMake and autotools, and removes older GCC<4.6 warning workarounds that are no longer needed.

🤖 Was this summary useful? React with 👍 or 👎

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread lib/curl_setup.h Resolved
@vszakats
vszakats requested a review from Copilot March 17, 2026 23:27
@vszakats

Copy link
Copy Markdown
Member Author

augment review

@augmentcode augmentcode Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes how the codebase guards #pragma GCC diagnostic push/pop by introducing and using a single CURL_HAVE_DIAG macro (Clang or GCC >= 4.6), avoiding build issues with older GCC versions and simplifying warning-flag logic.

Changes:

  • Add CURL_HAVE_DIAG to lib/curl_setup.h and replace scattered __GNUC__/__clang__ checks across lib/tool/tests with CURL_HAVE_DIAG.
  • Remove the test-only CURL_GNUC_DIAG macro and update unit/libtest/server sources accordingly.
  • Update Autotools + CMake “picky warnings” logic to keep it disabled for GCC < 4.6 (since local diagnostic suppression is unavailable there).

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/unit/unit3200.c Use CURL_HAVE_DIAG to guard diagnostic push/pop around overlength string literals.
tests/unit/unit2604.c Use CURL_HAVE_DIAG to guard diagnostic push/pop around overlength string literals.
tests/unit/unit1652.c Switch to CURL_HAVE_DIAG while keeping GCC-only warning suppression (excluding Clang).
tests/unit/unit1398.c Use CURL_HAVE_DIAG to guard diagnostic push/pop for format-warning suppression.
tests/server/util.c Use CURL_HAVE_DIAG to guard diagnostic push/pop around non-literal format warning suppression.
tests/libtest/lib557.c Use CURL_HAVE_DIAG to guard diagnostic push/pop around format warning suppressions.
tests/libtest/first.h Remove legacy CURL_GNUC_DIAG macro (now superseded by CURL_HAVE_DIAG).
src/tool_writeout.c Use CURL_HAVE_DIAG for guarding local suppression of -Wformat-nonliteral.
src/tool_main.c Use CURL_HAVE_DIAG for wmain()-related diagnostic suppression on Unicode builds.
src/tool_cb_prg.c Use CURL_HAVE_DIAG for guarding local suppression of -Wformat-nonliteral.
m4/curl-compilers.m4 Avoid enabling warning sets for GCC < 4.6; remove now-unneeded GCC<4.6 global suppression workarounds.
lib/version.c Use CURL_HAVE_DIAG to guard VLA-warning suppression around brotli headers.
lib/vauth/spnego_gssapi.c Use CURL_HAVE_DIAG on Apple builds to guard deprecated-declarations suppression push/pop.
lib/vauth/krb5_gssapi.c Use CURL_HAVE_DIAG on Apple builds to guard deprecated-declarations suppression push/pop.
lib/socks_gssapi.c Use CURL_HAVE_DIAG on Apple builds to guard deprecated-declarations suppression push/pop.
lib/mprintf.c Use CURL_HAVE_DIAG to guard local suppression of -Wformat-nonliteral.
lib/ldap.c Use CURL_HAVE_DIAG on Apple builds to guard deprecated-declarations suppression push/pop.
lib/if2ip.c Use CURL_HAVE_DIAG on AIX builds to guard local warning suppression around system headers.
lib/ftp.c Use CURL_HAVE_DIAG to guard local suppression for unsigned time_t warning cases (DJGPP/Amiga).
lib/curlx/snprintf.c Use CURL_HAVE_DIAG to guard local suppression of -Wformat-nonliteral (Windows wrapper).
lib/curl_setup.h Define CURL_HAVE_DIAG for Clang or GCC >= 4.6 as the single guard for diagnostic pragmas.
lib/curl_gssapi.c Use CURL_HAVE_DIAG on Apple builds to guard deprecated-declarations suppression push/pop.
lib/content_encoding.c Use CURL_HAVE_DIAG to guard VLA-warning suppression around brotli headers.
docs/examples/sendrecv.c Clarify intent to keep GCC diagnostic suppression at file scope for GCC < 4.6 compatibility.
CMake/PickyWarnings.cmake Keep picky warnings disabled for GCC < 4.6; remove now-unneeded GCC<4.6 global suppression workarounds.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@vszakats vszakats changed the title gcc: guard #pragma diagnostic for <4.6 in core code, disable picky warnings gcc: guard #pragma diagnostic in core code for <4.6, disable picky warnings Mar 17, 2026
@vszakats vszakats closed this in 578ee6b Mar 18, 2026
@vszakats
vszakats deleted the ancientgcc branch March 18, 2026 10:34
outcast36 pushed a commit to greearb/curl that referenced this pull request Jun 3, 2026
…warnings

Extend `#pragma diagnostic push`/`pop` guards to the whole codebase
(from tests and examples only) to disable it for GCC <4.6. Rename guard
to `CURL_HAVE_DIAG` and make it include llvm/clang to be interchangeable
with `__GNUC__ || __clang__` in this context.

The above means no longer disabling certain warnings locally, so pair
this with disabling all picky warnings for GCC <4.6.

Also:
- drop global workarounds for misbehaving GCC <4.6 compiler warnings.
  Not needed with picky warnings disabled.

Reported-by: fds242 on github
Reported-by: Sergey Fedorov
Thanks-to: Orgad Shaneh
Follow-up to f07a98a curl#20366
Fixes curl#20892
Fixes curl#20924
Closes curl#20902
Closes curl#20907
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

[Regression] 8.19.0 fails to build with gcc-4.2 due to pragmas inside functions 8.19.0 breaks compilation with ancient GCC (eg GCC 4.2)

3 participants