Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / format / format.functions / format_to.locale.verify.cpp
blobf3eb3f1d1dc3db1d4bbd3c67c6de45201d6c6027
1 //===----------------------------------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 // UNSUPPORTED: no-localization
11 // TODO FMT This test should not require std::to_chars(floating-point)
12 // XFAIL: availability-fp_to_chars-missing
14 // Basic test to validate ill-formed code is properly detected.
16 // <format>
18 // template<class Out, class... Args>
19 // Out format_to(Out out, const locale& loc,
20 // format-string<Args...> fmt, const Args&... args);
21 // template<class Out, class... Args>
22 // Out format_to(Out out, const locale& loc,
23 // wformat-string<Args...> fmt, const Args&... args);
25 #include <format>
26 #include <locale>
28 #include "test_macros.h"
30 extern char* out;
31 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
32 extern wchar_t* wout;
33 #endif
35 // clang-format off
37 void f() {
38 std::format_to(out, std::locale(), "{"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
39 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
41 std::format_to(out, std::locale(), "}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
42 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
44 std::format_to(out, std::locale(), "{}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
45 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
47 std::format_to(out, std::locale(), "{0}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
48 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
50 std::format_to(out, std::locale(), "{:-}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
51 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
53 std::format_to(out, std::locale(), "{:#}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
54 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
56 std::format_to(out, std::locale(), "{:L}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
57 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
59 std::format_to(out, std::locale(), "{0:{0}}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
60 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
62 std::format_to(out, std::locale(), "{:.42d}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
63 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
65 std::format_to(out, std::locale(), "{:d}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
66 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
68 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
69 std::format_to(wout, std::locale(), L"{"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
70 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
72 std::format_to(wout, std::locale(), L"}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
73 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
75 std::format_to(wout, std::locale(), L"{}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
76 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
78 std::format_to(wout, std::locale(), L"{0}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
79 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
81 std::format_to(wout, std::locale(), L"{:-}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
82 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
84 std::format_to(wout, std::locale(), L"{:#}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
85 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
87 std::format_to(wout, std::locale(), L"{:L}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
88 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
90 std::format_to(wout, std::locale(), L"{0:{0}}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
91 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
93 std::format_to(wout, std::locale(), L"{:.42d}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
94 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
96 std::format_to(wout, std::locale(), L"{:d}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
97 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
98 #endif