Skip to content

Fix nested_format_specs buffer context construction - #4963

Open
Tyagiquamar wants to merge 1 commit into
fmtlib:mainfrom
Tyagiquamar:fix-nested-format-specs-buffer-ctx
Open

Tyagiquamar wants to merge 1 commit into
fmtlib:mainfrom
Tyagiquamar:fix-nested-format-specs-buffer-ctx

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Problem

In nested_format_specs::write, buffer_ctx was constructed directly as FormatContext(basic_appender<Char>(buf), ctx.args(), ctx.locale()). When FormatContext is not parameterized with basic_appender<Char> (such as when custom contexts or different output iterators are passed, e.g. during compilation/custom formatters with nested formatted ranges like std::array or tuples), attempting to construct FormatContext directly with basic_appender<Char> leads to template instantiation and iterator mismatch errors (#4949).

Solution

  • Explicitly instantiate basic_format_context<basic_appender<Char>, Char> for the temporary buffer context in nested_format_specs::write().

Validation

  • Validated in Linux container with GCC 14:
    • Built and passed 100% of tests in ranges-test (42/42 tests) and compile-test (19/19 tests).

…mat_specs

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
@Tyagiquamar
Tyagiquamar requested a review from vitaut as a code owner October 1, 2026 11:46

@vitaut vitaut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems to move the mismatch from the output iterator to the argument pack. ctx.args() has type basic_format_args<FormatContext>, while the new buffer context expects basic_format_args<basic_format_context<basic_appender<Char>, Char>>, and there is no conversion between those when FormatContext is a generic_context.

Could you add the exact #4949 reproducer to compile-test.cc? I believe this still fails to instantiate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants