[libcxx-commits] [libcxx] [libc++] Mark __mbstate_t.h module as textual header (PR #200940)

Zibi Sarbinowski via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 10 06:58:57 PDT 2026


https://github.com/zibi2 updated https://github.com/llvm/llvm-project/pull/200940

>From 50053313d94a68e928ab7f33ab84008672b4e367 Mon Sep 17 00:00:00 2001
From: Zibi Sarbinowski <zibi at ca.ibm.com>
Date: Mon, 1 Jun 2026 16:28:17 -0400
Subject: [PATCH 1/3] Mark __mbstate_t.h module as textual header

---
 libcxx/include/module.modulemap.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 2ccb455b7408d..24c122d1ce331 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -2490,6 +2490,7 @@ module std_wctype_h [system] {
 
 // This header is used by other C compatibility headers so it needs to be in its own module.
 module std_private_mbstate_t [system] {
-  header "__mbstate_t.h"
+  // marked as textual to avoid circular depandancy between this module and std_wctype_h.
+  textual header "__mbstate_t.h"
   export *
 }

>From 0ec72242c1ee320a1687b7f8e7ba7aee0aceade8 Mon Sep 17 00:00:00 2001
From: Zibi Sarbinowski <zibi at ca.ibm.com>
Date: Fri, 5 Jun 2026 11:36:32 -0400
Subject: [PATCH 2/3] Update libcxx/include/module.modulemap.in

Co-authored-by: Louis Dionne <ldionne.2 at gmail.com>
---
 libcxx/include/module.modulemap.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 24c122d1ce331..161f38758ff05 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -2490,7 +2490,7 @@ module std_wctype_h [system] {
 
 // This header is used by other C compatibility headers so it needs to be in its own module.
 module std_private_mbstate_t [system] {
-  // marked as textual to avoid circular depandancy between this module and std_wctype_h.
+  // marked as textual to avoid circular dependency between this module and std_wctype_h.
   textual header "__mbstate_t.h"
   export *
 }

>From dc4773ad96e143020fdccc0360d683c6281ae2e5 Mon Sep 17 00:00:00 2001
From: Zibi Sarbinowski <zibi at ca.ibm.com>
Date: Wed, 10 Jun 2026 14:13:58 +0000
Subject: [PATCH 3/3] Add guard to prevent cycle of including __mbstate_t.h
 header

---
 libcxx/include/module.modulemap.in | 3 +--
 libcxx/include/wchar.h             | 6 ++++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/libcxx/include/module.modulemap.in b/libcxx/include/module.modulemap.in
index 161f38758ff05..2ccb455b7408d 100644
--- a/libcxx/include/module.modulemap.in
+++ b/libcxx/include/module.modulemap.in
@@ -2490,7 +2490,6 @@ module std_wctype_h [system] {
 
 // This header is used by other C compatibility headers so it needs to be in its own module.
 module std_private_mbstate_t [system] {
-  // marked as textual to avoid circular dependency between this module and std_wctype_h.
-  textual header "__mbstate_t.h"
+  header "__mbstate_t.h"
   export *
 }
diff --git a/libcxx/include/wchar.h b/libcxx/include/wchar.h
index a932dd266b862..84ae7379fccf9 100644
--- a/libcxx/include/wchar.h
+++ b/libcxx/include/wchar.h
@@ -119,8 +119,10 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
 #  ifndef _LIBCPP_WCHAR_H
 #    define _LIBCPP_WCHAR_H
 
-#    include <__mbstate_t.h> // provide mbstate_t
-#    include <stddef.h>      // provide size_t
+#    if !__has_include_next(<wchar.h>)
+#      include <__mbstate_t.h> // provide mbstate_t
+#      include <stddef.h>      // provide size_t
+#    endif
 
 // Determine whether we have const-correct overloads for wcschr and friends.
 #    if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)



More information about the libcxx-commits mailing list