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
6 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
10 // TODO FMT This test should not require std::to_chars(floating-point)
11 // XFAIL: availability-fp_to_chars-missing
15 // Basic test to validate ill-formed code is properly detected.
17 // template<class Out, class... Args>
18 // Out format_to(Out out, format-string<Args...> fmt, const Args&... args);
19 // template<class Out, class... Args>
20 // Out format_to(Out out, wformat-string<Args...> fmt, const Args&... args);
24 #include "test_macros.h"
27 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
34 std::format_to(out
, "{"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
35 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
37 std::format_to(out
, "}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
38 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
40 std::format_to(out
, "{}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
41 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
43 std::format_to(out
, "{0}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
44 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
46 std::format_to(out
, "{:-}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
47 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
49 std::format_to(out
, "{:#}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
50 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
52 std::format_to(out
, "{:L}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
53 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
55 std::format_to(out
, "{0:{0}}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
56 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
58 std::format_to(out
, "{:.42d}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
59 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
61 std::format_to(out
, "{:d}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
62 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
64 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
65 std::format_to(wout
, L
"{"); // 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 std::format_to(wout
, L
"}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
69 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
71 std::format_to(wout
, L
"{}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
72 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
74 std::format_to(wout
, L
"{0}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
75 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
77 std::format_to(wout
, L
"{:-}", L
"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
78 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
80 std::format_to(wout
, L
"{:#}", L
"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
81 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
83 std::format_to(wout
, L
"{:L}", L
"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
84 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
86 std::format_to(wout
, L
"{0:{0}}", L
"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
87 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
89 std::format_to(wout
, L
"{:.42d}", L
"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
90 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
92 std::format_to(wout
, L
"{:d}", L
"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
93 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}