[llvm-branch-commits] [clang] release/23.x: [C++20] [Modules] Handling merging predefined decls from std (#219151) (PR #219865)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Aug 30 19:29:12 PDT 2026


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/219865

Backport 52774473867e49b5891ab9381accf4e5a3ce0024

Requested by: @frederick-vs-ja

>From dc5701dd47b9423dcd8f9e47df1f90b77bcdc2f6 Mon Sep 17 00:00:00 2001
From: Chuanqi Xu <yedeng.yd at linux.alibaba.com>
Date: Thu, 27 Aug 2026 20:35:27 +0800
Subject: [PATCH] [C++20] [Modules] Handling merging predefined decls from std
 (#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.

(cherry picked from commit 52774473867e49b5891ab9381accf4e5a3ce0024)
---
 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 27fe259af3717..6a25a799aa219 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18387,7 +18387,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 llvm-branch-commits mailing list