[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,67 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// UNSUPPORTED: no-localization
+
+// <text_encoding>
+
+#include <functional>
+#include <text_encoding>
+
+#include "test_macros.h"
+
+int main(int, char**) {
+ std::text_encoding te = std::text_encoding();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ te.mib();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ te.name();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ te.aliases();
+
+#ifndef TEST_HAS_NO_LOCALIZATION
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ te.environment();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ te.environment_is<std::text_encoding::UTF8>();
+#endif
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ te.aliases();
+
+ auto alias = te.aliases();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ alias.begin();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ alias.end();
+
+ auto it = alias.begin();
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ *it;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ it[0];
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ it + 1;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ it - 1;
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ it - it;
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::hash<std::text_encoding>()(std::text_encoding::id::ASCII);
+
+ // Clang does not emit a nodiscard warning for consteval functions with [[nodiscard]]: See issue #141536
+ // expected-warning at +1 {{expression result unused}}
+ std::text_encoding::literal();
----------------
frederick-vs-ja wrote:
I think we can move this line to a separated `consteval` function and verify the warning message in the usual way. I used such technique in #200760.
https://github.com/llvm/llvm-project/pull/141312
More information about the libcxx-commits
mailing list