[clang] [C++20] [Modules] Handling merging predefined decls from std (PR #219151)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 27 02:22:36 PDT 2026
https://github.com/ChuanqiXu9 created https://github.com/llvm/llvm-project/pull/219151
Close https://github.com/llvm/llvm-project/issues/218152
This was only reported in windows as MSSTL chose to implement std module by wrapping the STL into extern "C++", which is different from libstdc++ and libc++.
But technically this is not specific to windows and we're able to preoduce it in linux although we won't face it in linux.
>From 95d31fddf49ff295c810a9de0828e3c7a562702d Mon Sep 17 00:00:00 2001
From: Chuanqi Xu <chuanqi.xcq at alibaba-inc.com>
Date: Thu, 27 Aug 2026 17:18:33 +0800
Subject: [PATCH] [C++20] [Modules] Handling merging predefined decls from std
Close https://github.com/llvm/llvm-project/issues/218152
This was only reported in windows as MSSTL chose to implement
std module by wrapping the STL into extern "C++", which is
different from libstdc++ and libc++.
But technically this is not specific to windows and we're
able to preoduce it in linux although we won't face it
in linux.
---
clang/lib/Sema/SemaDecl.cpp | 2 +-
clang/test/Modules/pr218152.cppm | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
create mode 100644 clang/test/Modules/pr218152.cppm
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a99fcb56d1138..0a8b8bb7ec61a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18506,7 +18506,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
}
if (getLangOpts().CPlusPlus && Name && DC && StdNamespace &&
- DC->Equals(getStdNamespace())) {
+ DC->getRedeclContext()->Equals(getStdNamespace())) {
if (Name->isStr("bad_alloc")) {
// This is a declaration of or a reference to "std::bad_alloc".
isStdBadAlloc = true;
diff --git a/clang/test/Modules/pr218152.cppm b/clang/test/Modules/pr218152.cppm
new file mode 100644
index 0000000000000..c7b82372f42d6
--- /dev/null
+++ b/clang/test/Modules/pr218152.cppm
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+export module fake_std;
+
+extern "C++" {
+namespace std {
+ using size_t = decltype(sizeof 0);
+ export enum class align_val_t : size_t {};
+} // namespace std
+
+export void *operator new(std::size_t, std::align_val_t);
+
+namespace std {
+void foo() { align_val_t x{}; }
+} // namespace std
+} // extern "C++"
More information about the cfe-commits
mailing list