Skip to content

Commit b109ea2

Browse files
committed
[C++20] [Modules] Warn for importing implementation partition unit in interface units
1 parent dee058f commit b109ea2

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ def warn_deprecated_literal_operator_id: Warning<
439439
"is deprecated">, InGroup<DeprecatedLiteralOperator>, DefaultIgnore;
440440
def warn_reserved_module_name : Warning<
441441
"%0 is a reserved name for a module">, InGroup<ReservedModuleIdentifier>;
442+
def warn_import_implementation_partition_unit_in_interface_unit : Warning<
443+
"it is not suggested to import implementation partition unit in interface unit">,
444+
InGroup<DiagGroup<"import-implementation-partition-unit-in-interface-unit">>;
442445

443446
def warn_parameter_size: Warning<
444447
"%0 is a large (%1 bytes) pass-by-value argument; "

clang/lib/Sema/SemaModule.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,13 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
650650
else
651651
VisibleModules.setVisible(Mod, ImportLoc);
652652

653+
assert((!Mod->isModulePartitionImplementation() || getCurrentModule()) &&
654+
"We can only import a partition unit in a named module.");
655+
if (Mod->isModulePartitionImplementation() &&
656+
getCurrentModule()->isModuleInterfaceUnit())
657+
Diag(ImportLoc,
658+
diag::warn_import_implementation_partition_unit_in_interface_unit);
659+
653660
checkModuleImportContext(*this, Mod, ImportLoc, CurContext);
654661

655662
// FIXME: we should support importing a submodule within a different submodule

clang/test/CXX/module/module.import/p2.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ void test() {
3030
}
3131

3232
//--- UseInPartA.cppm
33-
// expected-no-diagnostics
3433
export module M:partA;
35-
import :impl;
34+
import :impl; // expected-warning {{it is not suggested to import implementation partition unit in interface unit}}
3635
void test() {
3736
A a;
3837
}

clang/test/Modules/cxx20-10-3-ex1.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module M:PartImpl;
3737
export module M;
3838
// error: exported partition :Part is an implementation unit
3939
export import :PartImpl; // expected-error {{module partition implementations cannot be exported}}
40+
// expected-warning@-1 {{it is not suggested to import implementation partition unit in interface unit}}
4041

4142
//--- std10-3-ex1-tu3.cpp
4243
export module M:Part;

0 commit comments

Comments
 (0)