Index: clang/include/clang/Sema/Sema.h =================================================================== --- clang/include/clang/Sema/Sema.h +++ clang/include/clang/Sema/Sema.h @@ -2994,11 +2994,11 @@ /// \param ExportLoc The location of the 'export' keyword, if any. /// \param ImportLoc The location of the 'import' keyword. /// \param Path The module toplevel name as an access path. - /// \param Partition The module partition name as an access path. + /// \param IsPartition If the name is for a partition. DeclResult ActOnModuleImport(SourceLocation StartLoc, SourceLocation ExportLoc, SourceLocation ImportLoc, ModuleIdPath Path, - ModuleIdPath Partition = {}); + bool IsPartition = false); DeclResult ActOnModuleImport(SourceLocation StartLoc, SourceLocation ExportLoc, SourceLocation ImportLoc, Module *M, Index: clang/lib/Parse/Parser.cpp =================================================================== --- clang/lib/Parse/Parser.cpp +++ clang/lib/Parse/Parser.cpp @@ -2420,7 +2420,7 @@ // For C++20 modules, we can have "name" or ":Partition name" as valid input. SmallVector, 2> Path; - SmallVector, 2> Partition; + bool IsPartition = false; Module *HeaderUnit = nullptr; if (Tok.is(tok::header_name)) { // This is a header import that the preprocessor decided we should skip @@ -2435,10 +2435,12 @@ SourceLocation ColonLoc = ConsumeToken(); if (!getLangOpts().CPlusPlusModules) Diag(ColonLoc, diag::err_unsupported_module_partition) - << SourceRange(ColonLoc, Partition.back().second); + << SourceRange(ColonLoc, Path.back().second); // Recover by leaving partition empty. - else if (ParseModuleName(ColonLoc, Partition, /*IsImport*/ true)) + else if (ParseModuleName(ColonLoc, Path, /*IsImport*/ true)) return nullptr; + else + IsPartition = true; } else { if (ParseModuleName(ImportLoc, Path, /*IsImport*/ true)) return nullptr; @@ -2457,7 +2459,6 @@ // Diagnose mis-imports. bool SeenError = true; - bool HasPart = !Partition.empty(); switch (ImportState) { case Sema::ModuleImportState::ImportAllowed: SeenError = false; @@ -2465,7 +2466,7 @@ case Sema::ModuleImportState::FirstDecl: case Sema::ModuleImportState::NotACXX20Module: // We can only import a partition within a module purview. - if (HasPart) + if (IsPartition) Diag(ImportLoc, diag::err_partition_import_outside_module); else SeenError = false; @@ -2474,7 +2475,7 @@ // We can only have pre-processor directives in the global module // fragment. We can, however have a header unit import here. if (!HeaderUnit) - Diag(ImportLoc, diag::err_import_in_wrong_fragment) << HasPart << 0; + Diag(ImportLoc, diag::err_import_in_wrong_fragment) << IsPartition << 0; else SeenError = false; break; @@ -2485,7 +2486,7 @@ SeenError = false; break; case Sema::ModuleImportState::PrivateFragment: - Diag(ImportLoc, diag::err_import_in_wrong_fragment) << HasPart << 1; + Diag(ImportLoc, diag::err_import_in_wrong_fragment) << IsPartition << 1; break; } if (SeenError) { @@ -2497,9 +2498,9 @@ if (HeaderUnit) Import = Actions.ActOnModuleImport(StartLoc, ExportLoc, ImportLoc, HeaderUnit); - else if (!Path.empty() || !Partition.empty()) + else if (!Path.empty()) Import = Actions.ActOnModuleImport(StartLoc, ExportLoc, ImportLoc, Path, - Partition); + IsPartition); ExpectAndConsumeSemi(diag::err_module_expected_semi); if (Import.isInvalid()) return nullptr; Index: clang/lib/Sema/SemaModule.cpp =================================================================== --- clang/lib/Sema/SemaModule.cpp +++ clang/lib/Sema/SemaModule.cpp @@ -365,13 +365,10 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, SourceLocation ExportLoc, SourceLocation ImportLoc, ModuleIdPath Path, - ModuleIdPath Partition) { + bool IsPartition) { - bool IsPartition = !Partition.empty(); bool Cxx20Mode = getLangOpts().CPlusPlusModules || getLangOpts().ModulesTS; assert((!IsPartition || Cxx20Mode) && "partition seen in non-C++20 code?"); - assert((!IsPartition || Path.empty()) && - "trying to import a partition with its named module specified?"); // For a C++20 module name, flatten into a single identifier with the source // location of the first component. @@ -386,9 +383,9 @@ // otherwise, the name of the importing named module. ModuleName = NamedMod->getPrimaryModuleInterfaceName().str(); ModuleName += ":"; - ModuleName += stringFromPath(Partition); - ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Partition[0].second}; - Partition = ModuleIdPath(ModuleNameLoc); + ModuleName += stringFromPath(Path); + ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second}; + Path = ModuleIdPath(ModuleNameLoc); } else if (Cxx20Mode) { ModuleName = stringFromPath(Path); ModuleNameLoc = {PP.getIdentifierInfo(ModuleName), Path[0].second}; @@ -410,13 +407,11 @@ } Module *Mod = getModuleLoader().loadModule( - ImportLoc, IsPartition ? Partition : Path, Module::AllVisible, - /*IsInclusionDirective=*/false); + ImportLoc, Path, Module::AllVisible, /*IsInclusionDirective=*/false); if (!Mod) return true; - return ActOnModuleImport(StartLoc, ExportLoc, ImportLoc, Mod, - IsPartition ? Partition : Path); + return ActOnModuleImport(StartLoc, ExportLoc, ImportLoc, Mod, Path); } /// Determine whether \p D is lexically within an export-declaration.