[clang][deps] Fix dependency scanner misidentifying 'import::' as module partition (#148674)

The dependency directive scanner was incorrectly classifying namespaces
such as `import::inner xi` as directives. According to P1857R3, `import` should
not be treated as a directive when followed by `::`.
This change fixes that behavior.
This commit is contained in:
Naveen Seth Hanig 2025-07-14 20:37:30 +02:00 committed by GitHub
parent ec2e21a14d
commit ce8c19ffc5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -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))

View File

@ -1151,6 +1151,19 @@ TEST(MinimizeSourceToDependencyDirectivesTest, ObjCMethodArgs) {
EXPECT_STREQ("<TokBeforeEOF>\n", Out.data());
}
TEST(MinimizeSourceToDependencyDirectivesTest,
CxxModulesImportScopeResolution) {
SmallString<16> Out;
SmallVector<dependency_directives_scan::Token, 2> Tokens;
SmallVector<Directive, 1> Directives;
StringRef Source = "import::inner xi = {};'\n"
"module::inner yi = {};";
ASSERT_FALSE(
minimizeSourceToDependencyDirectives(Source, Out, Tokens, Directives));
EXPECT_STREQ("<TokBeforeEOF>\n", Out.data());
}
TEST(MinimizeSourceToDependencyDirectivesTest, TokensBeforeEOF) {
SmallString<128> Out;