aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r--clang/lib/Sema/SemaModule.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index b251507..0606b3a4 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -403,10 +403,16 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
}
// Diagnose self-import before attempting a load.
+ // [module.import]/9
+ // A module implementation unit of a module M that is not a module partition
+ // shall not contain a module-import-declaration nominating M.
+ // (for an implementation, the module interface is imported implicitly,
+ // but that's handled in the module decl code).
+
if (getLangOpts().CPlusPlusModules && isCurrentModulePurview() &&
getCurrentModule()->Name == ModuleName) {
- Diag(ImportLoc, diag::err_module_self_import)
- << ModuleName << getLangOpts().CurrentModule;
+ Diag(ImportLoc, diag::err_module_self_import_cxx20)
+ << ModuleName << !ModuleScopes.back().ModuleInterface;
return true;
}
@@ -440,8 +446,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
// of the same top-level module. Until we do, make it an error rather than
// silently ignoring the import.
// FIXME: Should we warn on a redundant import of the current module?
- if (!getLangOpts().CPlusPlusModules &&
- Mod->getTopLevelModuleName() == getLangOpts().CurrentModule &&
+ if (Mod->getTopLevelModuleName() == getLangOpts().CurrentModule &&
(getLangOpts().isCompilingModule() || !getLangOpts().ModulesTS)) {
Diag(ImportLoc, getLangOpts().isCompilingModule()
? diag::err_module_self_import
@@ -482,7 +487,12 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
if (!ModuleScopes.empty())
Context.addModuleInitializer(ModuleScopes.back().Module, Import);
- if (!ModuleScopes.empty() && ModuleScopes.back().ModuleInterface) {
+ // A module (partition) implementation unit shall not be exported.
+ if (getLangOpts().CPlusPlusModules && Mod && ExportLoc.isValid() &&
+ Mod->Kind == Module::ModuleKind::ModulePartitionImplementation) {
+ Diag(ExportLoc, diag::err_export_partition_impl)
+ << SourceRange(ExportLoc, Path.back().second);
+ } else if (!ModuleScopes.empty() && ModuleScopes.back().ModuleInterface) {
// Re-export the module if the imported module is exported.
// Note that we don't need to add re-exported module to Imports field
// since `Exports` implies the module is imported already.
@@ -494,7 +504,9 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
// [module.interface]p1:
// An export-declaration shall inhabit a namespace scope and appear in the
// purview of a module interface unit.
- Diag(ExportLoc, diag::err_export_not_in_module_interface) << 0;
+ Diag(ExportLoc, diag::err_export_not_in_module_interface)
+ << (!ModuleScopes.empty() &&
+ !ModuleScopes.back().ImplicitGlobalModuleFragment);
} else if (getLangOpts().isCompilingModule()) {
Module *ThisModule = PP.getHeaderSearchInfo().lookupModule(
getLangOpts().CurrentModule, ExportLoc, false, false);