aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2021-12-23 21:12:28 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2021-12-23 21:14:13 +0800
commit86b001a94172ac625f17f381c971dad3b9367278 (patch)
treef5ca06cf637d3dc3d7ae0aed16859bc4971d99f9
parent2810c3403e421560ad3e97053ca7227f81596daf (diff)
downloadllvm-86b001a94172ac625f17f381c971dad3b9367278.zip
llvm-86b001a94172ac625f17f381c971dad3b9367278.tar.gz
llvm-86b001a94172ac625f17f381c971dad3b9367278.tar.bz2
[C++20] [Modules] Mark imported module as imported if not exported
In C++20 Modules, imported module which doesn't get exported wouldn't be recorded. This patch would record such modules to avoid possible incorrect visibility problems. Reviewed By: urnathan Differential Revision: https://reviews.llvm.org/D116098
-rw-r--r--clang/lib/Sema/SemaModule.cpp9
-rw-r--r--clang/test/Modules/module-transtive-instantiation.cpp6
2 files changed, 10 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index f497199..a4b9f3c 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -383,11 +383,18 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
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);
}
diff --git a/clang/test/Modules/module-transtive-instantiation.cpp b/clang/test/Modules/module-transtive-instantiation.cpp
index 2c5c7ea..b44f0bb 100644
--- a/clang/test/Modules/module-transtive-instantiation.cpp
+++ b/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@Inputs/module-transtive-instantiation/bar.cppm:5 {{definition of 'G' must be imported from module 'Templ' before it is required}}
- // expected-note@-1 {{in instantiation of function template specialization 'bar<int>' requested here}}
- // expected-note@Inputs/module-transtive-instantiation/Templ.cppm:3 {{definition here is not reachable}}
+ return bar<int>();
}