Skip to content

Commit 7a75927

Browse files
committed
[clang][deps] Recognize 'module;' in dependency directive scanner
With this change, the dependency directive scanner now properly identifies "module;" as a directive, as per P1857R3. Previously, the global module fragment was not recognized by the scanner.
1 parent 4775b96 commit 7a75927

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

clang/lib/Lex/DependencyDirectivesScanner.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,13 @@ bool Scanner::lexModule(const char *&First, const char *const End) {
728728
return false;
729729
break;
730730
}
731+
case ';': {
732+
// Handle the global module fragment `module;`.
733+
if (Id == "module" && !Export)
734+
break;
735+
skipLine(First, End);
736+
return false;
737+
}
731738
case '<':
732739
case '"':
733740
break;

clang/unittests/Lex/DependencyDirectivesScannerTest.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,16 +1122,17 @@ ort \
11221122
)";
11231123
ASSERT_FALSE(
11241124
minimizeSourceToDependencyDirectives(Source, Out, Tokens, Directives));
1125-
EXPECT_STREQ("#include \"textual-header.h\"\nexport module m;"
1125+
EXPECT_STREQ("module;#include \"textual-header.h\"\nexport module m;"
11261126
"exp\\\nort import:l[[rename]];"
11271127
"import<<=3;import a b d e d e f e;"
11281128
"import foo[[no_unique_address]];import foo();"
11291129
"import f(:sefse);import f(->a=3);"
11301130
"<TokBeforeEOF>\n",
11311131
Out.data());
1132-
ASSERT_EQ(Directives.size(), 11u);
1133-
EXPECT_EQ(Directives[0].Kind, pp_include);
1134-
EXPECT_EQ(Directives[1].Kind, cxx_export_module_decl);
1132+
ASSERT_EQ(Directives.size(), 12u);
1133+
EXPECT_EQ(Directives[0].Kind, cxx_module_decl);
1134+
EXPECT_EQ(Directives[1].Kind, pp_include);
1135+
EXPECT_EQ(Directives[2].Kind, cxx_export_module_decl);
11351136
}
11361137

11371138
TEST(MinimizeSourceToDependencyDirectivesTest, ObjCMethodArgs) {

0 commit comments

Comments
 (0)