Skip to content

Commit ece6382

Browse files
committed
[clang-scan-deps] Only check eod token in C++ modules
Signed-off-by: yronglin <[email protected]>
1 parent b75b5ba commit ece6382

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

clang/lib/Lex/DependencyDirectivesScanner.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ bool Scanner::lexModuleDirectiveBody(DirectiveKind Kind, const char *&First,
505505
First = Previous;
506506
return false;
507507
}
508-
if (Tok.isOneOf(tok::eof, tok::eod))
508+
if (Tok.is(tok::eof) || (LangOpts.CPlusPlusModules && Tok.is(tok::eod)))
509509
return reportError(
510510
DirectiveLoc,
511511
diag::err_dep_source_scanner_missing_semi_after_at_import);
@@ -865,10 +865,6 @@ bool Scanner::lexPPLine(const char *&First, const char *const End) {
865865
if (*First == '@')
866866
return lexAt(First, End);
867867

868-
// Handle module directives for C++20 modules.
869-
if (*First == 'i' || *First == 'e' || *First == 'm')
870-
return lexModule(First, End);
871-
872868
if (*First == '_') {
873869
if (isNextIdentifierOrSkipLine("_Pragma", First, End))
874870
return lex_Pragma(First, End);
@@ -880,8 +876,27 @@ bool Scanner::lexPPLine(const char *&First, const char *const End) {
880876
TheLexer.setParsingPreprocessorDirective(true);
881877
auto ScEx2 = make_scope_exit(
882878
[&]() { TheLexer.setParsingPreprocessorDirective(false); });
879+
880+
// Since P1857R3, the standard handling C++ module/import as a directive:
881+
//
882+
// [cpp.pre]p1:
883+
// A preprocessing directive consists of a sequence of preprocessing tokens
884+
// that satisfies the following constraints: At the start of translation
885+
// phase 4, the first preprocessing token in the sequence, referred to as a
886+
// directive-introducing token, begins with the first character in the source
887+
// file (optionally after whitespace containing no new-line characters) or
888+
// follows whitespace containing at least one new-line character, and is
889+
// - a # preprocessing token, or
890+
// - an import preprocessing token immediately followed on the same logical
891+
// source line by a header-name, <, identifier, string-literal, or :
892+
// preprocessing token, or
893+
// - a module preprocessing token immediately followed on the same logical
894+
// source line by an identifier, :, or ; preprocessing token, or
895+
// - an export preprocessing token immediately followed on the same logical
896+
// source line by one of the two preceding forms.
883897
if (*First == 'i' || *First == 'e' || *First == 'm')
884898
return lexModule(First, End);
899+
885900
// Lex '#'.
886901
const dependency_directives_scan::Token &HashTok = lexToken(First, End);
887902
if (HashTok.is(tok::hashhash)) {

0 commit comments

Comments
 (0)