diff options
author | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2024-09-14 14:45:50 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-14 14:45:50 +0800 |
commit | 82034aca30ad8b08aadfe6b6b9048f5cdfa1d3ff (patch) | |
tree | 5ca3f8c44d1052983c82d6dcee8f710530223bb8 /clang/lib/Sema/SemaModule.cpp | |
parent | 390b82dd4c485ec64cf8a6c52fb73e391792262e (diff) | |
download | llvm-82034aca30ad8b08aadfe6b6b9048f5cdfa1d3ff.zip llvm-82034aca30ad8b08aadfe6b6b9048f5cdfa1d3ff.tar.gz llvm-82034aca30ad8b08aadfe6b6b9048f5cdfa1d3ff.tar.bz2 |
[C++20] [Modules] Warn for importing implementation partition unit in interface units (#108493)
Recently, there are multiple false positive issue reports about the
reachability of implementation partition units:
- https://github.com/llvm/llvm-project/issues/105882
- https://github.com/llvm/llvm-project/issues/101348
- https://lists.isocpp.org/core/2024/08/16232.php
And according to our use experience for modules, we find it is a pretty
good practice to not import implementation partition units in the
interface units. It can help developers to have a pretty good mental
model for when to use an implementation partition unit: that any unit in
the module but not in the module interfaces can be in the implementation
partition unit.
So I think it is good to add the diagnostics.
Diffstat (limited to 'clang/lib/Sema/SemaModule.cpp')
-rw-r--r-- | clang/lib/Sema/SemaModule.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 3b84e7b..d6ebc38 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -650,6 +650,14 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, else VisibleModules.setVisible(Mod, ImportLoc); + assert((!Mod->isModulePartitionImplementation() || getCurrentModule()) && + "We can only import a partition unit in a named module."); + if (Mod->isModulePartitionImplementation() && + getCurrentModule()->isModuleInterfaceUnit()) + Diag(ImportLoc, + diag::warn_import_implementation_partition_unit_in_interface_unit) + << Mod->Name; + checkModuleImportContext(*this, Mod, ImportLoc, CurContext); // FIXME: we should support importing a submodule within a different submodule |