[VPlan] Perform DT expensive input DT verification earlier (NFC).
[llvm-project.git] / libcxx / test / std / utilities / format / format.functions / format_to.locale.verify.cpp
blob488110ab2aa2b8933e02a5a664463d6397a7f164
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // UNSUPPORTED: no-localization
12 // TODO FMT This test should not require std::to_chars(floating-point)
13 // XFAIL: availability-fp_to_chars-missing
15 // Basic test to validate ill-formed code is properly detected.
17 // <format>
19 // template<class Out, class... Args>
20 // Out format_to(Out out, const locale& loc,
21 // format-string<Args...> fmt, const Args&... args);
22 // template<class Out, class... Args>
23 // Out format_to(Out out, const locale& loc,
24 // wformat-string<Args...> fmt, const Args&... args);
26 #include <format>
27 #include <locale>
29 #include "test_macros.h"
31 extern char* out;
32 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
33 extern wchar_t* wout;
34 #endif
36 // clang-format off
38 void f() {
39 std::format_to(out, std::locale(), "{"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
40 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
42 std::format_to(out, std::locale(), "}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
43 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
45 std::format_to(out, std::locale(), "{}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
46 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
48 std::format_to(out, std::locale(), "{0}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
49 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
51 std::format_to(out, std::locale(), "{:-}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
52 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
54 std::format_to(out, std::locale(), "{:#}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
55 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
57 std::format_to(out, std::locale(), "{:L}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
58 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
60 std::format_to(out, std::locale(), "{0:{0}}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
61 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
63 std::format_to(out, std::locale(), "{:.42d}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
64 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
66 std::format_to(out, std::locale(), "{:d}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
67 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
69 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
70 std::format_to(wout, std::locale(), L"{"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
71 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
73 std::format_to(wout, std::locale(), L"}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
74 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
76 std::format_to(wout, std::locale(), L"{}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
77 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
79 std::format_to(wout, std::locale(), L"{0}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
80 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
82 std::format_to(wout, std::locale(), L"{:-}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
83 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
85 std::format_to(wout, std::locale(), L"{:#}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
86 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
88 std::format_to(wout, std::locale(), L"{:L}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
89 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
91 std::format_to(wout, std::locale(), L"{0:{0}}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
92 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
94 std::format_to(wout, std::locale(), L"{:.42d}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
95 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
97 std::format_to(wout, std::locale(), L"{:d}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
98 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
99 #endif