Skip to content

Fix output position for compiled variant and expected formatting - #4968

Merged
vitaut merged 1 commit into
fmtlib:mainfrom
fhgffy:fix-compiled-alternative-output
Oct 7, 2026
Merged

vitaut merged 1 commit into
fmtlib:mainfrom
fhgffy:fix-compiled-alternative-output

Conversation

@fhgffy

@fhgffy fhgffy commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Compiled formatting into a char* buffer produces 42) for std::variant<int>{42} instead of variant(42). std::expected and std::unexpected have the same issue: their prefixes advance the local iterator, but the nested formatter receives the original context output position.

Advance the context to that iterator in write_escaped_alternative before calling the nested formatter. Add regression tests for all three wrappers, nested variants, monostate, returned output positions with surrounding text, and unchanged string/character escaping.

Validation on upstream main at 9197f51593dab5f637454a8889fb9638e737711a, using GCC 15.1.0 (MinGW) and CMake 4.3.2:

  • All three new tests fail before the fix and pass afterward.
  • C++23 Debug: complete available CTest suite passes (22/22).
  • C++17 Debug: compile-test and std-test pass (2/2); C++23-only expected cases are not exercised in this configuration.
  • clang-format 21.1.8 and git diff --check pass.

Linux, MSVC, and older compiler configurations have not been run locally.

@fhgffy
fhgffy marked this pull request as ready for review October 3, 2026 23:34
@fhgffy
fhgffy requested a review from vitaut as a code owner October 3, 2026 23:34
@vitaut
vitaut merged commit 10cda46 into fmtlib:main Oct 7, 2026
47 checks passed
@vitaut

vitaut commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix!

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