[clang] [C++][Modules] Don't check '<' after 'import' when converting import pp-token to contextual keyword (PR #191004)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 9 08:55:32 PDT 2026
================
@@ -1380,13 +1380,34 @@ bool Preprocessor::HandleModuleContextualKeyword(Token &Result) {
llvm::SaveAndRestore<bool> SavedParsingPreprocessorDirective(
CurPPLexer->ParsingPreprocessorDirective, true);
- // The next token may be an angled string literal after import keyword.
- llvm::SaveAndRestore<bool> SavedParsingFilemame(
- CurPPLexer->ParsingFilename,
- Result.getIdentifierInfo()->isImportKeyword());
+ bool ParsingFilename = false;
+ if (Result.getIdentifierInfo()->isImportKeyword()) {
+ if (getLangOpts().Digraphs && CurLexer &&
+ CurLexer->getCurrentBufferOffset() + 2 < CurLexer->getBuffer().size()) {
+ // If the import preprocessing token folled by a digraph character '<:',
+ // the import preprocessing should not traited as a import contextual
+ // keyword. Eg.
+ // int
+ // import <:10
+ // :>;
+ //
+ // This is a array definition, and equivalent to:
+ //
+ // int import[10];
+ const char *CurPtr = CurLexer->getBufferLocation();
+ CurPtr = Lexer::SkipHorizontalWhitespace(CurPtr);
+ auto C0 = Lexer::getCharAndSizeNoWarn(CurPtr, getLangOpts());
+ auto C1 = Lexer::getCharAndSizeNoWarn(CurPtr + C0.Size, getLangOpts());
----------------
yronglin wrote:
Good catch! I have implemented the fix in another way. This issue will no longer exists.
https://github.com/llvm/llvm-project/pull/191004
More information about the cfe-commits
mailing list