[clang] [C++][Modules][Preprocessor] Clang should not convert a import preprocessing token to contextual keyword if a digraph character following import (PR #191004)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 8 09:32:07 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();
----------------
cor3ntin wrote:
```suggestion
// If the import preprocessing token is followed by a digraph such as '<:',
// the import preprocessing should not be treated as an import contextual
// keyword. Eg.
// int
// import <:10
// :>;
//
// This is an array definition and equivalent to `int import[10];`
const char *CurPtr = CurLexer->getBufferLocation();
```
https://github.com/llvm/llvm-project/pull/191004
More information about the cfe-commits
mailing list