Avoid -Wdangling-reference false positives in locale helpers - #4876
Open
viordash wants to merge 1 commit into
Open
Avoid -Wdangling-reference false positives in locale helpers#4876viordash wants to merge 1 commit into
viordash wants to merge 1 commit into
Conversation
Contributor
|
Could you provide a godbolt CMake-project (since it requires PCH) repro? |
Author
|
Here is a CMake project repro: https://godbolt.org/z/vfcfWThT7 Removing the target_precompile_headers() line makes it quiet. |
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.
GCC 13/14 warns in two locale helpers when a precompiled header is used:
It is a false positive:
locale_ref::get<std::locale>()returns a copy, and thereference returned by
std::use_facetstays valid as long as any copy of that localeexists. GCC only warns when the declaration comes from a precompiled header; with
<locale>included normally it stays quiet. Reproducible with plain<locale>,no fmt involved:
This patch binds the locale copy to a named variable at both call sites, so no reference
is bound to a temporary. Same single copy, no behaviour change, and the lifetime becomes
explicit instead of relying on the "valid while any copy exists" guarantee.
Checked with GCC 13.4: warnings gone when a PCH is in use, ctest passes 21/21, and
locale-aware output is unchanged
Originally filed against spdlog, which vendors these files (gabime/spdlog#3638), and
closed there with a pointer to this repository.