diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/docs/ReleaseNotes.rst | 2 | ||||
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaModule.cpp | 8 | ||||
-rw-r--r-- | clang/test/CXX/module/module.import/p2.cpp | 3 | ||||
-rw-r--r-- | clang/test/Modules/cxx20-10-3-ex1.cpp | 1 |
5 files changed, 16 insertions, 2 deletions
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 3929a9f..79b154e 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -303,6 +303,8 @@ Improvements to Clang's diagnostics - Clang now warns for u8 character literals used in C23 with ``-Wpre-c23-compat`` instead of ``-Wpre-c++17-compat``. +- Clang now diagnose when importing module implementation partition units in module interface units. + Improvements to Clang's time-trace ---------------------------------- diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 50f27ee..e506811 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -442,6 +442,10 @@ def warn_deprecated_literal_operator_id: Warning< "is deprecated">, InGroup<DeprecatedLiteralOperator>, DefaultIgnore; def warn_reserved_module_name : Warning< "%0 is a reserved name for a module">, InGroup<ReservedModuleIdentifier>; +def warn_import_implementation_partition_unit_in_interface_unit : Warning< + "importing an implementation partition unit in a module interface is not recommended. " + "Names from %0 may not be reachable">, + InGroup<DiagGroup<"import-implementation-partition-unit-in-interface-unit">>; def warn_parameter_size: Warning< "%0 is a large (%1 bytes) pass-by-value argument; " 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 diff --git a/clang/test/CXX/module/module.import/p2.cpp b/clang/test/CXX/module/module.import/p2.cpp index ef60068..6b8e32f 100644 --- a/clang/test/CXX/module/module.import/p2.cpp +++ b/clang/test/CXX/module/module.import/p2.cpp @@ -30,9 +30,8 @@ void test() { } //--- UseInPartA.cppm -// expected-no-diagnostics export module M:partA; -import :impl; +import :impl; // expected-warning {{importing an implementation partition unit in a module interface is not recommended.}} void test() { A a; } diff --git a/clang/test/Modules/cxx20-10-3-ex1.cpp b/clang/test/Modules/cxx20-10-3-ex1.cpp index 99b88c7..82ecb40 100644 --- a/clang/test/Modules/cxx20-10-3-ex1.cpp +++ b/clang/test/Modules/cxx20-10-3-ex1.cpp @@ -37,6 +37,7 @@ module M:PartImpl; export module M; // error: exported partition :Part is an implementation unit export import :PartImpl; // expected-error {{module partition implementations cannot be exported}} + // expected-warning@-1 {{importing an implementation partition unit in a module interface is not recommended.}} //--- std10-3-ex1-tu3.cpp export module M:Part; |