Skip to content

Fix unreachable code warning in range formatter - #4932

Open
Zhao0335 wants to merge 1 commit into
fmtlib:mainfrom
Zhao0335:fix-4930-msvc-unreachable-range-formatter
Open

Fix unreachable code warning in range formatter#4932
Zhao0335 wants to merge 1 commit into
fmtlib:mainfrom
Zhao0335:fix-4930-msvc-unreachable-range-formatter

Conversation

@Zhao0335

@Zhao0335 Zhao0335 commented Sep 6, 2026

Copy link
Copy Markdown

Fixes #4930.

The range formatter constructor returned from a compile-time branch for every
non-set range, leaving the bracket customization after the return. New MSVC
versions diagnose that statement as unreachable when sequence range formatters
are instantiated.

Invert the condition and only customize brackets for set ranges. This preserves
the behavior for both pre-C++20 and C++20 builds while allowing if constexpr
to discard the unused branch.

Testing:

  • MSVC 19.44 /W4: the ranges.h C4702 warning reproduced before the change
    and is absent after it
  • ranges-test passed
  • full MSVC Release build passed
  • full CTest: 20/22 passed; chrono-test.locale and
    unicode-test.legacy_locale fail under this machine's zh-CN locale

@Zhao0335
Zhao0335 requested a review from vitaut as a code owner September 6, 2026 16:55
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.

Unreachable code warning in ranges.h for msvc with /W4

1 participant