diff options
author | Iain Sandoe <iain@sandoe.co.uk> | 2022-01-30 14:11:57 +0000 |
---|---|---|
committer | Iain Sandoe <iain@sandoe.co.uk> | 2022-02-26 11:27:08 +0000 |
commit | 1a76d2563940e6b4bfcb9e77b8a4d1d3f0cc7d30 (patch) | |
tree | b0e5ca8e2434a9caffb7ec6ac221bc123c1c61ff /clang/lib/Sema/SemaModule.cpp | |
parent | 4d006520b8c0cc3a52913b4665bf741c737e5592 (diff) | |
download | llvm-1a76d2563940e6b4bfcb9e77b8a4d1d3f0cc7d30.zip llvm-1a76d2563940e6b4bfcb9e77b8a4d1d3f0cc7d30.tar.gz llvm-1a76d2563940e6b4bfcb9e77b8a4d1d3f0cc7d30.tar.bz2 |
[C++20][Modules][5/8] Diagnose wrong import/export for partition CMIs.
We cannot export partition implementation CMIs, but we can export the content
of partition interface CMIs.
Differential Revision: https://reviews.llvm.org/D118588
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r-- | clang/lib/Sema/SemaModule.cpp | 24 |
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); |