aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/std
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-03-21 11:15:06 +0000
committerJonathan Wakely <jwakely@redhat.com>2024-03-23 11:07:57 +0000
commit543585046d17add37c0108b06d2884d0e03cedde (patch)
tree834ee3ae39143ee53af82e424d13d02a0603b654 /libstdc++-v3/testsuite/std
parent3763fb8970d7515a4a3be2152604140965303031 (diff)
downloadgcc-543585046d17add37c0108b06d2884d0e03cedde.zip
gcc-543585046d17add37c0108b06d2884d0e03cedde.tar.gz
gcc-543585046d17add37c0108b06d2884d0e03cedde.tar.bz2
libstdc++: Disable std::formatter specializations (LWG 3944)
This was just approved in Tokyo as a DR for C++23. It doesn't affect us yet, because we don't implement the __cpp_lib_format_ranges features. We can add the disabled specializations and add a testcase now though. libstdc++-v3/ChangeLog: * include/std/format (formatter): Disable specializations that would allow sequences of narrow characters to be formatted as wchar_t without conversion, as per LWG 3944. * testsuite/std/format/formatter/lwg3944.cc: New test.
Diffstat (limited to 'libstdc++-v3/testsuite/std')
-rw-r--r--libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc b/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc
new file mode 100644
index 0000000..ff5f075
--- /dev/null
+++ b/libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc
@@ -0,0 +1,31 @@
+// { dg-do compile { target c++20 } }
+// { dg-options "-Wno-unused-result" }
+
+// LWG 3944. Formatters converting sequences of char to sequences of wchar_t
+
+#include <format>
+
+void test_lwg3944()
+{
+ // Ill-formed in C++20 and C++23
+ const char* cstr = "hello";
+ char* str = const_cast<char*>(cstr);
+ std::format(L"{}", str); // { dg-error "here" }
+ std::format(L"{}",cstr); // { dg-error "here" }
+
+ // Ill-formed in C++20
+ // In C++23 they give L"['h', 'e', 'l', 'l', 'o']"
+ std::format(L"{}", "hello"); // { dg-error "here" }
+ std::format(L"{}", std::string_view("hello")); // { dg-error "here" }
+ std::format(L"{}", std::string("hello")); // { dg-error "here" }
+#ifdef __cpp_lib_format_ranges
+ // LWG 3944 does not change this, it's still valid.
+ std::format(L"{}", std::vector{'h', 'e', 'l', 'l', 'o'});
+#endif
+}
+
+// { dg-error "std::formatter must be specialized" "" { target *-*-* } 0 }
+// { dg-prune-output "use of deleted function" }
+// { dg-prune-output "no matching function" }
+// { dg-prune-output "has no member named 'parse'" }
+// { dg-prune-output "not a constant expression" }