1 //===----------------------------------------------------------------------===//
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
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.
19 // template<class... Args>
20 // string format(const locale& loc, format-string<Args...> fmt, const Args&... args);
21 // template<class... Args>
22 // wstring format(const locale& loc, wformat-string<Args...> fmt, const Args&... args);
27 #include "test_macros.h"
32 TEST_IGNORE_NODISCARD
std::format(std::locale(), "{"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
33 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
35 TEST_IGNORE_NODISCARD
std::format(std::locale(), "}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
36 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
38 TEST_IGNORE_NODISCARD
std::format(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 TEST_IGNORE_NODISCARD
std::format(std::locale(), "{0}"); // 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 TEST_IGNORE_NODISCARD
std::format(std::locale(), "{:-}", "Forty-two"); // 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 TEST_IGNORE_NODISCARD
std::format(std::locale(), "{:#}", "Forty-two"); // 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 TEST_IGNORE_NODISCARD
std::format(std::locale(), "{:L}", "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 TEST_IGNORE_NODISCARD
std::format(std::locale(), "{0:{0}}", "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 TEST_IGNORE_NODISCARD
std::format(std::locale(), "{:.42d}", "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 TEST_IGNORE_NODISCARD
std::format(std::locale(), "{:d}", "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 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
63 TEST_IGNORE_NODISCARD
std::format(std::locale(), L
"{"); // 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 TEST_IGNORE_NODISCARD
std::format(std::locale(), L
"}"); // 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 TEST_IGNORE_NODISCARD
std::format(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 TEST_IGNORE_NODISCARD
std::format(std::locale(), L
"{0}"); // 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 TEST_IGNORE_NODISCARD
std::format(std::locale(), L
"{:-}", L
"Forty-two"); // 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 TEST_IGNORE_NODISCARD
std::format(std::locale(), L
"{:#}", L
"Forty-two"); // 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 TEST_IGNORE_NODISCARD
std::format(std::locale(), L
"{: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 TEST_IGNORE_NODISCARD
std::format(std::locale(), L
"{0:{0}}", 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 TEST_IGNORE_NODISCARD
std::format(std::locale(), L
"{:.42d}", 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 TEST_IGNORE_NODISCARD
std::format(std::locale(), L
"{:d}", 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}}