Limit Clang diagnostic suppressions to fmt declarations - #4948
Merged
Merged
Conversation
format.h and std.h suppress Clang warnings for declarations provided by fmt, but do not restore the previous diagnostic state. Including either header therefore also hides the corresponding warning in unrelated consumer code. Use fmt's existing Clang diagnostic push and pop macros to limit -Wweak-vtables to format_error and -Wbit-int-extension to the two _BitInt aliases. Signed-off-by: Yongqiang Tian <yqtian668@gmail.com>
vitaut
approved these changes
Sep 18, 2026
Contributor
|
Merged, thanks |
Contributor
Author
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Clang diagnostic pragmas remain in effect until another pragma changes or
restores them. Two public fmt headers suppress warnings for fmt declarations
but do not restore the diagnostic state before returning to consumer code:
format.hignores-Wweak-vtablesbefore declaringformat_error;std.hignores-Wbit-int-extensionbefore declaring thebitintandubitintaliases.Because neither suppression has a matching push and pop, declarations after
the include inherit it. For example, this consumer class normally triggers
-Wweak-vtables, but the warning disappears after includingformat.h:The same occurs for a consumer
_BitIntalias after includingstd.h:The requested
-Wbit-int-extensiondiagnostic is suppressed along with fmt'sown aliases. This branch is enabled by default with Clang 15 and later; I used
FMT_USE_BITINT=1to exercise the same branch with the available Clang 14compiler.
The matched probes produced the following results:
main-Wweak-vtables_BitIntalias with-Wbit-int-extensionThus, including either header currently disables a warning that the consumer
explicitly requested for its own code. In a build that promotes the warning to
an error, the header also changes whether that consumer code is accepted.
This change brackets each suppression with fmt's existing Clang diagnostic
push/pop macros. The warnings remain suppressed for the fmt declarations that
need them, while the consumer's previous diagnostic state is restored
immediately afterward. The macros remain no-ops for non-Clang compilers.
Validation:
FMT_PEDANTIC=ONandFMT_WERROR=ONsucceeds;