Forward outer context in nested_formatter for dynamic precision#4750
Open
barry3406 wants to merge 1 commit intofmtlib:mainfrom
Open
Forward outer context in nested_formatter for dynamic precision#4750barry3406 wants to merge 1 commit intofmtlib:mainfrom
barry3406 wants to merge 1 commit intofmtlib:mainfrom
Conversation
Dynamic width/precision arg indices inside a nested_formatter referred to
the arguments of the intermediate format_to invocation, not the original
outer format call, so "{:.{}}" failed with 'argument not found'.
Make nested() accept the outer context and plumb its args and locale
through nested_view, so the inner formatter resolves dynamic specs
against the original argument list.
Fixes fmtlib#3860.
vitaut
requested changes
Apr 24, 2026
Comment on lines
+4112
to
+4114
| auto outer_ctx = OuterContext(ctx.out(), view.outer_args, view.outer_loc); | ||
| auto it = view.fmt->format(*view.value, outer_ctx); | ||
| ctx.advance_to(it); |
Contributor
There was a problem hiding this comment.
This will only work if iterators are compatible (same context types) so there shouldn't be parameterization on OuterContext.
| } | ||
|
|
||
| TEST(format_test, nested_formatter_dynamic_precision) { | ||
| // https://github.com/fmtlib/fmt/issues/3860 |
Contributor
There was a problem hiding this comment.
This is not needed, let's remove.
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.
Dynamic precision like
{:.{}}on anested_formatterpreviously failed withargument not found, because the inner formatter stored anarg_refthat was being resolved against the intermediateformat_tocontext rather than the original outer format call.nested()now takes the outerformat_context, andnested_viewplumbs the outer args and locale through toformatter<nested_view>::format, so dynamic width/precision references resolve against the user's original argument list. The one-argumentnested(value)overload is kept for backward compatibility; existing static-precision uses are unaffected.Fixes #3860.