Fix enable_ifs for map formatter: map formatter requires std::pair formatter but never uses it #2944
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.
I am referring to L455 in the formatter definition if
is_map<T>
is true:fmt/include/fmt/ranges.h
Lines 449 to 456 in 5682338
Please note:
T
is the map type. We are usingdetail::uncvref_type<T>
here, which gives the type of a dereferenced iterator ofT
, i.e. astd::pair<const K,V>
in case of astd::map<K, V>
.This formatter is never used, though, as key and value are formatted separately:
fmt/include/fmt/ranges.h
Lines 476 to 479 in 5682338
Thus, a formatter for the
std::pair
is not needed, or more generally speeking: L455 isn't checking the correct thing.I stumbled upon this with a custom map which isn't using
std::pair
internally, and doesn't have a formatter for the internalpair
type. But this shouldn't hinder this formatter from being used.Additionally, the
pair<K, V>
formatter is no guarantee that we have formatters forK
andV
of the map (although it probably would be bad code not to use them in the pair formatter).