[PATCH] D116098: [C++20] [Modules] Mark imported module as imported if not exported

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 23 04:52:01 PST 2021

This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG368318bcce66: [C++20] [Coroutines] Mark imported module as imported if not exported (authored by ChuanqiXu).

  rG LLVM Github Monorepo




Index: clang/test/Modules/module-transtive-instantiation.cpp
--- clang/test/Modules/module-transtive-instantiation.cpp
+++ clang/test/Modules/module-transtive-instantiation.cpp
@@ -3,11 +3,9 @@
 // RUN: %clang_cc1 -std=c++20 %S/Inputs/module-transtive-instantiation/Templ.cppm -emit-module-interface -o %t/Templ.pcm
 // RUN: %clang_cc1 -std=c++20 %S/Inputs/module-transtive-instantiation/bar.cppm  -emit-module-interface -fprebuilt-module-path=%t -o %t/bar.pcm
 // RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %s -fsyntax-only -verify
+// expected-no-diagnostics
 import bar;
 int foo() {
-    // FIXME: It shouldn't be an error. Since the `G` is already imported in bar.
-    return bar<int>(); // expected-error at Inputs/module-transtive-instantiation/bar.cppm:5 {{definition of 'G' must be imported from module 'Templ' before it is required}}
-                       // expected-note at -1 {{in instantiation of function template specialization 'bar<int>' requested here}}
-                       // expected-note at Inputs/module-transtive-instantiation/Templ.cppm:3 {{definition here is not reachable}}
+  return bar<int>();
Index: clang/lib/Sema/SemaModule.cpp
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -383,11 +383,18 @@
   if (!ModuleScopes.empty())
     Context.addModuleInitializer(ModuleScopes.back().Module, Import);
-  // Re-export the module if needed.
   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.
     if (ExportLoc.isValid() || getEnclosingExportDecl(Import))
       getCurrentModule()->Exports.emplace_back(Mod, false);
+    else
+      getCurrentModule()->Imports.insert(Mod);
   } else if (ExportLoc.isValid()) {
+    // [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);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116098.396010.patch
Type: text/x-patch
Size: 2259 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211223/7652d529/attachment.bin>

More information about the cfe-commits mailing list