[clang] 7977cb0 - [C++20] [Modules] Diagnose invalid module interface for implementation unit (#215448)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 10 20:11:06 PDT 2026
Author: Chuanqi Xu
Date: 2026-08-11T03:11:00Z
New Revision: 7977cb020cca4755a45101ebd9f1dee705ca0eb3
URL: https://github.com/llvm/llvm-project/commit/7977cb020cca4755a45101ebd9f1dee705ca0eb3
DIFF: https://github.com/llvm/llvm-project/commit/7977cb020cca4755a45101ebd9f1dee705ca0eb3.diff
LOG: [C++20] [Modules] Diagnose invalid module interface for implementation unit (#215448)
Added:
Modified:
clang/lib/Sema/SemaModule.cpp
clang/test/Modules/GH204633.cppm
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 42c67cf89ed88..8a7bf172c8342 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -426,8 +426,10 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
// A Clang module or a header unit cannot serve as the primary module
// interface while recovering from an implementation unit declaration.
- if (Interface && !Interface->isNamedModule())
+ if (Interface && !Interface->isNamedModule()) {
+ Diag(ModuleLoc, diag::err_module_not_defined) << ModuleName;
return nullptr;
+ }
if (!Interface) {
Diag(ModuleLoc, diag::err_module_not_defined) << ModuleName;
diff --git a/clang/test/Modules/GH204633.cppm b/clang/test/Modules/GH204633.cppm
index 4bcd1200a5568..8651352013e67 100644
--- a/clang/test/Modules/GH204633.cppm
+++ b/clang/test/Modules/GH204633.cppm
@@ -9,15 +9,15 @@
// parser accepts this as a Clang module definition, while the C++ parser
// diagnoses it as a malformed module declaration.
//--- original.cppm
-// expected-error at +2 {{unexpected preprocessing token '{' after module name}}
-// expected-error at +1 {{module directive must end with a ';'}}
+// expected-error at +3 {{unexpected preprocessing token '{' after module name}}
+// expected-error at +2 {{module directive must end with a ';'}}
+// expected-error at +1 {{definition of module 'M' is not available}}
module M {}
// Build the conflicting Clang module inline.
//--- inline.cppm
-// expected-no-diagnostics
#pragma clang module build Foo
module Foo {}
#pragma clang module endbuild
-module Foo;
+module Foo; // expected-error {{definition of module 'Foo' is not available}}
More information about the cfe-commits
mailing list