[libcxx-commits] [libcxx] [libc++] LWG3767: `codecvt<charN_t, char8_t, mbstate_t>` incorrectly added to locale (PR #201749)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 4 22:26:42 PDT 2026


https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/201749

Implement it as a DR against C++20, patching P0482R6.

Fixes #105313.

>From ca78b355a6d98d72a3ca9c568f96cdcef726278f Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Fri, 5 Jun 2026 13:23:55 +0800
Subject: [PATCH] [libc++] LWG3767: `codecvt<charN_t, char8_t, mbstate_t>`
 incorrectly added to locale

Implement it as a DR against C++20, patching P0482R6.
---
 libcxx/docs/Status/Cxx2cIssues.csv            |  2 +-
 libcxx/include/__locale                       | 16 +++++++-----
 ..._char16_t_char8_t.depr_in_cxx20.verify.cpp | 26 +++++++++++++++++++
 ..._char32_t_char8_t.depr_in_cxx20.verify.cpp | 26 +++++++++++++++++++
 4 files changed, 63 insertions(+), 7 deletions(-)
 create mode 100644 libcxx/test/std/localization/locale.categories/category.ctype/locale.codecvt/codecvt_char16_t_char8_t.depr_in_cxx20.verify.cpp
 create mode 100644 libcxx/test/std/localization/locale.categories/category.ctype/locale.codecvt/codecvt_char32_t_char8_t.depr_in_cxx20.verify.cpp

diff --git a/libcxx/docs/Status/Cxx2cIssues.csv b/libcxx/docs/Status/Cxx2cIssues.csv
index 6a836c0491bb6..419e5755ed4a8 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -40,7 +40,7 @@
 "`LWG3990 <https://wg21.link/LWG3990>`__","Program-defined specializations of ``std::tuple`` and ``std::variant`` can't be properly supported","2023-11 (Kona)","|Complete|","21","`#105310 <https://github.com/llvm/llvm-project/issues/105310>`__",""
 "`LWG4001 <https://wg21.link/LWG4001>`__","``iota_view`` should provide ``empty``","2023-11 (Kona)","|Complete|","19","`#105311 <https://github.com/llvm/llvm-project/issues/105311>`__",""
 "","","","","","",""
-"`LWG3767 <https://wg21.link/LWG3767>`__","``codecvt<charN_t, char8_t, mbstate_t>`` incorrectly added to locale","2024-03 (Tokyo)","","","`#105313 <https://github.com/llvm/llvm-project/issues/105313>`__",""
+"`LWG3767 <https://wg21.link/LWG3767>`__","``codecvt<charN_t, char8_t, mbstate_t>`` incorrectly added to locale","2024-03 (Tokyo)","|Complete|","23","`#105313 <https://github.com/llvm/llvm-project/issues/105313>`__",""
 "`LWG3919 <https://wg21.link/LWG3919>`__","``enumerate_view`` may invoke UB for sized common non-forward underlying ranges","2024-03 (Tokyo)","|Complete|","23","`#105315 <https://github.com/llvm/llvm-project/issues/105315>`__",""
 "`LWG3950 <https://wg21.link/LWG3950>`__","``std::basic_string_view`` comparison operators are overspecified","2024-03 (Tokyo)","|Complete|","18","`#105316 <https://github.com/llvm/llvm-project/issues/105316>`__",""
 "`LWG3975 <https://wg21.link/LWG3975>`__","Specializations of ``basic_format_context`` should not be permitted","2024-03 (Tokyo)","|Nothing To Do|","","`#105317 <https://github.com/llvm/llvm-project/issues/105317>`__",""
diff --git a/libcxx/include/__locale b/libcxx/include/__locale
index 52066f5f84d24..33b1924db67c1 100644
--- a/libcxx/include/__locale
+++ b/libcxx/include/__locale
@@ -991,10 +991,11 @@ protected:
 
 #  if _LIBCPP_HAS_CHAR8_T
 
-// template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20
+// template <> class codecvt<char16_t, char8_t, mbstate_t> // C++20, deprecated in C++20
 
 template <>
-class _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base {
+class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char16_t, char8_t, mbstate_t>
+    : public locale::facet, public codecvt_base {
 public:
   typedef char16_t intern_type;
   typedef char8_t extern_type;
@@ -1154,10 +1155,11 @@ protected:
 
 #  if _LIBCPP_HAS_CHAR8_T
 
-// template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20
+// template <> class codecvt<char32_t, char8_t, mbstate_t> // C++20, deprecated in C++20
 
 template <>
-class _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char8_t, mbstate_t> : public locale::facet, public codecvt_base {
+class _LIBCPP_DEPRECATED_IN_CXX20 _LIBCPP_EXPORTED_FROM_ABI codecvt<char32_t, char8_t, mbstate_t>
+    : public locale::facet, public codecvt_base {
 public:
   typedef char32_t intern_type;
   typedef char8_t extern_type;
@@ -1263,8 +1265,10 @@ _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>; // d
 extern template class _LIBCPP_DEPRECATED_IN_CXX20
 _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>; // deprecated in C++20
 #  if _LIBCPP_HAS_CHAR8_T
-extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20
-extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20
+extern template class _LIBCPP_DEPRECATED_IN_CXX20
+_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char8_t, mbstate_t>; // C++20, deprecated in C++20
+extern template class _LIBCPP_DEPRECATED_IN_CXX20
+_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char8_t, mbstate_t>; // C++20, deprecated in C++20
 #  endif
 
 template <size_t _Np>
diff --git a/libcxx/test/std/localization/locale.categories/category.ctype/locale.codecvt/codecvt_char16_t_char8_t.depr_in_cxx20.verify.cpp b/libcxx/test/std/localization/locale.categories/category.ctype/locale.codecvt/codecvt_char16_t_char8_t.depr_in_cxx20.verify.cpp
new file mode 100644
index 0000000000000..904fbe85b1dfc
--- /dev/null
+++ b/libcxx/test/std/localization/locale.categories/category.ctype/locale.codecvt/codecvt_char16_t_char8_t.depr_in_cxx20.verify.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// codecvt<char16_t, char8_t, mbstate_t>
+//  deprecated in C++20, per LWG3767
+
+// REQUIRES: std-at-least-c++20
+// XFAIL: availability-char8_t_support-missing
+
+#include <locale>
+
+#include "../with_public_dtor.hpp"
+
+void test() {
+  // Don't test for the exact type since the underlying type of std::mbstate_t depends on implementation details.
+
+  // expected-warning-re at +1 {{'codecvt<char16_t, char8_t, {{.*}}>' is deprecated}}
+  [[maybe_unused]] with_public_dtor<std::codecvt<char16_t, char8_t, std::mbstate_t>> cvt("", 0);
+}
diff --git a/libcxx/test/std/localization/locale.categories/category.ctype/locale.codecvt/codecvt_char32_t_char8_t.depr_in_cxx20.verify.cpp b/libcxx/test/std/localization/locale.categories/category.ctype/locale.codecvt/codecvt_char32_t_char8_t.depr_in_cxx20.verify.cpp
new file mode 100644
index 0000000000000..17be9aeacdaeb
--- /dev/null
+++ b/libcxx/test/std/localization/locale.categories/category.ctype/locale.codecvt/codecvt_char32_t_char8_t.depr_in_cxx20.verify.cpp
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// <locale>
+
+// codecvt<char32_t, char8_t, mbstate_t>
+//  deprecated in C++20, per LWG3767
+
+// REQUIRES: std-at-least-c++20
+// XFAIL: availability-char8_t_support-missing
+
+#include <locale>
+
+#include "../with_public_dtor.hpp"
+
+void test() {
+  // Don't test for the exact type since the underlying type of std::mbstate_t depends on implementation details.
+
+  // expected-warning-re at +1 {{'codecvt<char32_t, char8_t, {{.*}}>' is deprecated}}
+  [[maybe_unused]] with_public_dtor<std::codecvt<char32_t, char8_t, std::mbstate_t>> cvt("", 0);
+}



More information about the libcxx-commits mailing list