Conversation
An extended-identifier macro name (bytes 0x80-0xFF) was accepted by #define without validating that its codepoints are allowed in an identifier for the active language standard, so e.g. `#define TM 42` using U+2122 was silently defined even though the parser rejects the same codepoint in a declaration. Closes Vexu#593
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.
What
Closes #593.
#define ™ 42(macro nameU+2122 TRADE MARK SIGN) was silently accepted, even though™is not a valid identifier character and the parser correctly rejects it in a declaration (int ™;→error: unexpected character <U+2122>).Fix
define()already rejects a macro name whose token isn't a macro identifier, but any byte in0x80..0xFFtokenizes as.extended_identifier, which passes that check without the codepoints ever being validated. Added a check that walks the extended-identifier name and confirms every codepoint is allowed in an identifier for the active language standard (reusingStandard.codepointAllowedInIdentifier, the same predicate the parser uses). On failure it emits the existingmacro_name_must_be_identifierdiagnostic, matching the message requested in the issue.This is standard-dependent and now matches the declaration path exactly: valid extended identifiers (e.g. Greek
α) are still accepted;™is rejected whereverint ™;would be rejected.Tests
test/cases/macro name must be an identifier.c.zig build test→478 passed; 33 skippedand9007 passed; 2 skipped.zig build test-fmtclean.477 passed; 1 failed), restoring it passes.#define α 42) still work, and that the#defineresult now matches the declaration path across-std=c99/c11/c17/c23.Happy to adjust.