Fix MSVC compilation issues caused by non-ASCII source characters - #293
Open
myd7349 wants to merge 1 commit into
Open
Fix MSVC compilation issues caused by non-ASCII source characters#293myd7349 wants to merge 1 commit into
myd7349 wants to merge 1 commit into
Conversation
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.
This patch fixes an issue where non-ASCII characters in the source code can cause compilation warnings or even errors in CJK locales.
For example, on my Windows 11 system with the Simplified Chinese locale, the local code page is CP936. Although the source files are encoded in UTF-8, as of Visual Studio 2026, the Microsoft compiler still cannot correctly read UTF-8 files without a BOM by default. As a result, it falls back to the system code page when parsing the source files, which can lead to the following warnings and errors:
Build log:
Screenshot:
A large number of
warning C4819messages can easily flood the build log and obscure other useful compiler output.I used the following script to identify and print the non-ASCII characters in the source code:
Output:
There are two ways to address this issue:
This PR uses a combination of these two approaches to minimize the changes while eliminating the compilation warnings and errors:
warning C4819messages in projects that consume the library./source-charset:utf-8.testing\blackhole.cppis left unchanged because it does not support the Windows platform.If you have any other preferences or suggestions for how this should be handled, please let me know, and I can update the PR accordingly.