================
@@ -610,6 +629,57 @@ void 
Preprocessor::SkipExcludedConditionalBlock(SourceLocation HashTokenLoc,
           continue;
         }
 
+        // There is actually no "skipped block" in the above because the module
+        // directive is not a text-line (https://wg21.link/cpp.pre#2) nor
+        // anything else that is allowed in a group
+        // (https://eel.is/c++draft/cpp.pre#nt:group-part).
+        //
+        // A preprocessor diagnostic (effective with -E) that triggers whenever
+        // a module directive is encountered where a control-line or a 
text-line
+        // is required.
+        if (getLangOpts().CPlusPlusModules && Tok.isAtStartOfLine() &&
+            Tok.is(tok::raw_identifier) &&
+            (Tok.getRawIdentifier() == "export" ||
+             Tok.getRawIdentifier() == "module")) {
+          llvm::SaveAndRestore ModuleDirectiveSkipping(
+              LastTokenWasExportKeyword);
+          LastTokenWasExportKeyword.reset();
+          LookUpIdentifierInfo(Tok);
+          IdentifierInfo *II = Tok.getIdentifierInfo();
+
+          if (II->getName()[0] == 'e') {
+            HandleModuleContextualKeyword(Tok, Tok.isAtStartOfLine());
+            CurLexer->Lex(Tok);
+            if (Tok.is(tok::raw_identifier)) {
+              LookUpIdentifierInfo(Tok);
+              II = Tok.getIdentifierInfo();
+            }
+          }
+
+          if (II->getName()[0] == 'm') {
+            // HandleModuleContextualKeyword will look ahead next token, so
+            // exiting RawLexingMode.
----------------
cor3ntin wrote:

```suggestion
            // HandleModuleContextualKeyword changes the lexer state, so we 
need to save RawLexingMode 
```

https://github.com/llvm/llvm-project/pull/107168
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to