Skip to content

Build nolocale-test with /utf-8 on MSVC - #4919

Merged
vitaut merged 1 commit into
fmtlib:mainfrom
ethanstoner:fix/nolocale-test-utf8-msvc
Sep 6, 2026
Merged

Build nolocale-test with /utf-8 on MSVC#4919
vitaut merged 1 commit into
fmtlib:mainfrom
ethanstoner:fix/nolocale-test-utf8-msvc

Conversation

@ethanstoner

Copy link
Copy Markdown
Contributor

nolocale-test does not compile with MSVC when FMT_PEDANTIC is on:

include\fmt\base.h(455): error C2338: static_assert failed:
  'Unicode support requires compiling with /utf-8'

The target is built from ../src/format.cc directly (test/CMakeLists.txt:132), so it does not pick up the /utf-8 that CMakeLists.txt:255 adds to the fmt target. unicode-test already guards the same flag the same way at test/CMakeLists.txt:73-75, so this follows that.

It has not shown up in CI because the target only exists under FMT_PEDANTIC, and windows.yml does not set it, while linux.yml:211-212 and macos.yml:46 both do.

Checked at C++20 and C++23 with MSVC 19.44, since I wondered whether it was standard-specific. It is not, it fails at both. After the change the full build succeeds and ctest is 23/23 with FMT_PEDANTIC=ON.


Disclosure: written with AI assistance. The build output above is from my own machine.

@ethanstoner
ethanstoner requested a review from vitaut as a code owner September 4, 2026 14:33

@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.

Thanks for the PR. The fix makes sense but please address the inline comment.

Comment thread test/CMakeLists.txt
Comment on lines 135 to 136
target_compile_definitions(nolocale-test
PRIVATE FMT_STATIC_THOUSANDS_SEPARATOR=1)

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.

Let's add $<$<CXX_COMPILER_ID:MSVC>:/utf-8> here instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done, switched to $<$<CXX_COMPILER_ID:MSVC>:/utf-8>.

Rebuilt on MSVC 17 2022 with -DFMT_PEDANTIC=ON -DFMT_TEST=ON -DCMAKE_CXX_STANDARD=20: nolocale-test compiles, the full build has no errors, and ctest is 23/23. Reverting just this hunk still fails with error C2338: static_assert failed: 'Unicode support requires compiling with /utf-8' at base.h:455.

nolocale-test compiles src/format.cc directly, so it does not pick up the
/utf-8 that CMakeLists.txt adds to the fmt target. On MSVC the static_assert
in base.h then fires: "Unicode support requires compiling with /utf-8".

The target only exists under FMT_PEDANTIC, which the Windows workflow does not
set, so this has not shown up in CI. unicode-test already guards the same flag
the same way.
@ethanstoner
ethanstoner force-pushed the fix/nolocale-test-utf8-msvc branch from 2bc1443 to 3a241dd Compare September 6, 2026 19:42
@vitaut
vitaut merged commit 2d4d8a1 into fmtlib:main Sep 6, 2026
47 checks passed
@vitaut

vitaut commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Merged, thanks

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