Repository navigation
Pass bytes above 127 safely to the cctype classifiers, and skip a UTF-8 BOM - #1456
Open
helixsolara wants to merge 2 commits into
Open
helixsolara wants to merge 2 commits into
helixsolara wants to merge 2 commits into
Conversation
…-8 BOM. cppfront passed plain char values to isspace, isdigit, isxdigit, isalpha and isalnum. Where char is signed, as with MSVC, a byte above 127 becomes a negative int, which those functions don't accept: it is undefined behavior, and a debug build of cppfront stops with a CRT assertion dialog (isctype.cpp, c >= -1 && c <= 255). A source file saved with a UTF-8 byte order mark, as Visual Studio can write, hits this on its first line. common.h gains as_ctype, which converts through unsigned char, and every classifier call in the sources goes through it; cpp2util.h's is_id_char casts the same way. io.h also drops a byte order mark from the start of the first line, so it doesn't reach the lexer as source. The new regression test pure2-utf8-byte-order-mark.cpp2 starts with a byte order mark. A debug build without the fix fails the assertion on it; with the fix, run-tests.sh passes it with MSVC in both c++20 and c++latest, and its results for those are included. The other compilers' results aren't, since I could only run MSVC. All 192 existing regression tests transpile to the same .cpp and .cpp2.output as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first commit wrapped every direct call to a cctype classifier, but two places pass a classifier as a function to call later: move_next in io.h calls its predicate with a plain char, and source_line::indent in common.h gives &isspace to std::find_if_not over a std::string. Both now convert through unsigned char, move_next with as_ctype and indent with a lambda, since as_ctype is defined after it. All 192 regression tests still transpile to the same .cpp and .cpp2.output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
cppfront passes plain
charvalues toisspace,isdigit,isxdigit,isalphaandisalnum. Wherecharis signed (MSVC), a byte above 127 becomes a negativeint, which those functions don't accept: undefined behavior, and a debug build of cppfront stops with a CRT assertion dialog:A
.cpp2file saved with a UTF-8 byte order mark, which Visual Studio can write, hits this on its first line.Changes
common.hgainsas_ctype(char), which converts throughunsigned char, and every classifier call insource/goes through it.cpp2util.h'sis_id_charcasts the same way.io.hdrops a UTF-8 byte order mark from the start of the first line, so it doesn't reach the lexer as source.Tests
pure2-utf8-byte-order-mark.cpp2, which starts with a byte order mark. A debug build without the fix fails the assertion on it; with the fix it passesrun-tests.shwith MSVC (c++20andc++latest), whose results are included. I could only run MSVC, so the other compilers' result files aren't included..cppand.cpp2.outputas before.🤖 Generated with Claude Code