Debian Codegraph @

libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc

raw
1 // { dg-do compile { target c++20 } }
2 // { dg-options "-Wno-unused-result" }
3
4 // LWG 3944. Formatters converting sequences of char to sequences of wchar_t
5
6 #include <format>
7 #include <vector>
8
9 void test_lwg3944()
10 {
11 // Ill-formed in C++20 and C++23
12 const char* cstr = "hello";
13 char* str = const_cast<char*>(cstr);
14 std::format(L"{}", str); // { dg-error "here" }
15 std::format(L"{}",cstr); // { dg-error "here" }
16
17 // Ill-formed in C++20
18 std::format(L"{}", "hello"); // { dg-error "here" }
19 std::format(L"{}", std::string_view("hello")); // { dg-error "here" }
20 std::format(L"{}", std::string("hello")); // { dg-error "here" }
21 #ifdef __cpp_lib_format_ranges
22 // LWG 3944 does not change this, it's still valid.
23 std::format(L"{}", std::vector{'h', 'e', 'l', 'l', 'o'});
24 #endif
25 }
26
27 // { dg-error "std::formatter must be specialized" "" { target *-*-* } 0 }
28 // { dg-prune-output "use of deleted function" }
29 // { dg-prune-output "no matching function" }
30 // { dg-prune-output "has no member named 'parse'" }
31 // { dg-prune-output "not a constant expression" }