diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp b/clang/lib/Lex/DependencyDirectivesScanner.cpp index d894c265a07a..869c9cea566b 100644 --- a/clang/lib/Lex/DependencyDirectivesScanner.cpp +++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp @@ -722,6 +722,13 @@ bool Scanner::lexModule(const char *&First, const char *const End) { skipLine(First, End); return false; } + // A module partition starts with exactly one ':'. If we have '::', this is + // a scope resolution instead and shouldn't be recognized as a directive + // per P1857R3. + if (First + 1 != End && First[1] == ':') { + skipLine(First, End); + return false; + } // `import:(type)name` is a valid ObjC method decl, so check one more token. (void)lexToken(First, End); if (!tryLexIdentifierOrSkipLine(First, End)) diff --git a/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp b/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp index d2ef27155df9..46dbb4d4b91b 100644 --- a/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp +++ b/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp @@ -1151,6 +1151,19 @@ TEST(MinimizeSourceToDependencyDirectivesTest, ObjCMethodArgs) { EXPECT_STREQ("\n", Out.data()); } +TEST(MinimizeSourceToDependencyDirectivesTest, + CxxModulesImportScopeResolution) { + SmallString<16> Out; + SmallVector Tokens; + SmallVector Directives; + + StringRef Source = "import::inner xi = {};'\n" + "module::inner yi = {};"; + ASSERT_FALSE( + minimizeSourceToDependencyDirectives(Source, Out, Tokens, Directives)); + EXPECT_STREQ("\n", Out.data()); +} + TEST(MinimizeSourceToDependencyDirectivesTest, TokensBeforeEOF) { SmallString<128> Out;