[clang] [C++20] [Modules] Diagnose invalid module interface for implementation unit (PR #215448)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 10 19:36:52 PDT 2026
https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/215448
None
>From 3194e8e0463b3e321e6e803b02b5a5617cda4fa7 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu <chuanqi.xcq at alibaba-inc.com>
Date: Tue, 11 Aug 2026 10:35:09 +0800
Subject: [PATCH] [C++20] [Modules] Diagnose invalid module interface for
implementation unit
---
clang/lib/Sema/SemaModule.cpp | 4 +++-
clang/test/Modules/GH204633.cppm | 8 ++++----
2 files changed, 7 insertions(+), 5 deletions(-)
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