xref: /llvm-project/libcxx/test/std/utilities/format/format.functions/format.locale.verify.cpp (revision 6a54dfbfe534276d644d7f9c027f0deeb748dd53)
1aed5ddf8SMark de Wever //===----------------------------------------------------------------------===//
2*6a54dfbfSLouis Dionne //
3aed5ddf8SMark de Wever // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4aed5ddf8SMark de Wever // See https://llvm.org/LICENSE.txt for license information.
5aed5ddf8SMark de Wever // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6aed5ddf8SMark de Wever //
7aed5ddf8SMark de Wever //===----------------------------------------------------------------------===//
8aed5ddf8SMark de Wever 
9aed5ddf8SMark de Wever // UNSUPPORTED: c++03, c++11, c++14, c++17
10aed5ddf8SMark de Wever // UNSUPPORTED: no-localization
11aed5ddf8SMark de Wever 
123d334df5SLouis Dionne // TODO FMT This test should not require std::to_chars(floating-point)
13f0fc8c48SLouis Dionne // XFAIL: availability-fp_to_chars-missing
143d334df5SLouis Dionne 
15aed5ddf8SMark de Wever // Basic test to validate ill-formed code is properly detected.
16aed5ddf8SMark de Wever 
17aed5ddf8SMark de Wever // <format>
18aed5ddf8SMark de Wever 
19aed5ddf8SMark de Wever // template<class... Args>
20aed5ddf8SMark de Wever //   string format(const locale& loc, format-string<Args...> fmt, const Args&... args);
21aed5ddf8SMark de Wever // template<class... Args>
22aed5ddf8SMark de Wever //   wstring format(const locale& loc, wformat-string<Args...> fmt, const Args&... args);
23aed5ddf8SMark de Wever 
24aed5ddf8SMark de Wever #include <format>
25aed5ddf8SMark de Wever #include <locale>
26aed5ddf8SMark de Wever 
27aed5ddf8SMark de Wever #include "test_macros.h"
28aed5ddf8SMark de Wever 
29aed5ddf8SMark de Wever // clang-format off
30aed5ddf8SMark de Wever 
31aed5ddf8SMark de Wever void f() {
329c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), "{"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
33aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
34aed5ddf8SMark de Wever 
359c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), "}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
36aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
37aed5ddf8SMark de Wever 
389c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), "{}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
39aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
40aed5ddf8SMark de Wever 
419c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), "{0}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
42aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
43aed5ddf8SMark de Wever 
449c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), "{:-}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
45aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
46aed5ddf8SMark de Wever 
479c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), "{:#}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
48aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
49aed5ddf8SMark de Wever 
509c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), "{:L}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
51aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
52aed5ddf8SMark de Wever 
539c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), "{0:{0}}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
54aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
55aed5ddf8SMark de Wever 
569c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), "{:.42d}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
57aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
58aed5ddf8SMark de Wever 
599c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), "{:d}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
60aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
61aed5ddf8SMark de Wever 
62aed5ddf8SMark de Wever #ifndef TEST_HAS_NO_WIDE_CHARACTERS
639c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), L"{"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
64aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
65aed5ddf8SMark de Wever 
669c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), L"}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
67aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
68aed5ddf8SMark de Wever 
699c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), L"{}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
70aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
71aed5ddf8SMark de Wever 
729c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), L"{0}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
73aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
74aed5ddf8SMark de Wever 
759c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), L"{:-}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
76aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
77aed5ddf8SMark de Wever 
789c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), L"{:#}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
79aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
80aed5ddf8SMark de Wever 
819c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), L"{:L}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
82aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
83aed5ddf8SMark de Wever 
849c053e69SMark de Wever   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}}
85aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
86aed5ddf8SMark de Wever 
879c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), L"{:.42d}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
88aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
89aed5ddf8SMark de Wever 
909c053e69SMark de Wever   TEST_IGNORE_NODISCARD std::format(std::locale(), L"{:d}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
91aed5ddf8SMark de Wever   // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
92aed5ddf8SMark de Wever #endif
93aed5ddf8SMark de Wever }
94