[clang] [clang][Modules] make ActOnPrivateModuleFragmentDecl return non-null on success. (PR #223757)
Mahmoud Ahmed via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 15 09:51:43 PDT 2026
https://github.com/anondeveg updated https://github.com/llvm/llvm-project/pull/223757
>From 4fa951f3fb2e77a2cdb178f1216b23b5135efb47 Mon Sep 17 00:00:00 2001
From: Anondev <anondeveg at gmail.com>
Date: Tue, 15 Sep 2026 19:29:02 +0300
Subject: [PATCH] [clang][Modules] make ActOnPrivateModuleFragmentDecl return
non-null object on success.
---
clang/lib/Parse/Parser.cpp | 6 ++++--
clang/lib/Sema/SemaModule.cpp | 2 +-
clang/test/Modules/mismatched_global_module_sate.cppm | 5 +++++
3 files changed, 10 insertions(+), 3 deletions(-)
create mode 100644 clang/test/Modules/mismatched_global_module_sate.cppm
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index bad81ea92cd2db..319a9856551440 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -2360,12 +2360,14 @@ Parser::ParseModuleDecl(Sema::ModuleImportState &ImportState) {
SourceLocation PrivateLoc = ConsumeToken();
DiagnoseAndSkipCXX11Attributes();
ExpectAndConsumeSemi(diag::err_private_module_fragment_expected_semi);
+ auto Result = Actions.ActOnPrivateModuleFragmentDecl(ModuleLoc, PrivateLoc);
+ if(Result){
ImportState = ImportState == Sema::ModuleImportState::ImportAllowed
? Sema::ModuleImportState::PrivateFragmentImportAllowed
: Sema::ModuleImportState::PrivateFragmentImportFinished;
- return Actions.ActOnPrivateModuleFragmentDecl(ModuleLoc, PrivateLoc);
+ }
+ return nullptr;
}
-
SmallVector<IdentifierLoc, 2> Path;
if (ParseModuleName(ModuleLoc, Path, /*IsImport*/ false))
return nullptr;
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index d7a182fe5654ce..b769f133359e8d 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -566,7 +566,7 @@ Sema::ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc,
TU->setLocalOwningModule(PrivateModuleFragment);
// FIXME: Consider creating an explicit representation of this declaration.
- return nullptr;
+ return ConvertDeclToDeclGroup(TU);
}
DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc,
diff --git a/clang/test/Modules/mismatched_global_module_sate.cppm b/clang/test/Modules/mismatched_global_module_sate.cppm
new file mode 100644
index 00000000000000..417b8ad932afb1
--- /dev/null
+++ b/clang/test/Modules/mismatched_global_module_sate.cppm
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 --std=c++23 -fsyntax-only -verify %s
+// see ISSUE 219950
+module;
+module :private; // expected-error {{private module fragment declaration with no preceding module declaration}}
+export module Foo;
More information about the cfe-commits
mailing list