[libcxx-commits] [libcxx] [llvm] [libc++] Implement P1885R12: `<text_encoding>` (PR #141312)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 3 20:58:37 PDT 2026


================
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <text_encoding>
+
+// text_encoding::text_encoding() noexcept
+
+#include <cassert>
+#include <concepts>
+#include <text_encoding>
+#include <type_traits>
+
+constexpr bool test() {
+  std::same_as<std::text_encoding> decltype(auto) te = std::text_encoding();
+  assert(te.mib() == std::text_encoding::unknown);
+  assert(std::string_view("") == te.name());
+
+  return true;
+}
+
+int main(int, char**) {
+  // 1. Default constructor must be nothrow
+  {
+    static_assert(
+        std::is_nothrow_default_constructible<std::text_encoding>::value, "Must be nothrow default constructible");
+  }
+
+  // 2. Default constructing a text_encoding object makes it so that mib() == id::unknown, and its name is empty
+  {
+    test();
+    static_assert(test());
+  }
----------------
frederick-vs-ja wrote:

Let's use `_v` and avoid pointless `{}` (throughout all new test files). I think additional braces are only meaningful when there're local variables.
```suggestion
  // 1. Default constructor must be nothrow
  static_assert(std::is_nothrow_default_constructible_v<std::text_encoding>, "Must be nothrow default constructible");

  // 2. Default constructing a text_encoding object makes it so that mib() == id::unknown, and its name is empty
  test();
  static_assert(test());
```

https://github.com/llvm/llvm-project/pull/141312


More information about the libcxx-commits mailing list