| 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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 | // UNSUPPORTED: no-localization |
| 11 | |
| 12 | // TODO FMT This test should not require std::to_chars(floating-point) |
| 13 | // XFAIL: availability-fp_to_chars-missing |
| 14 | |
| 15 | // Basic test to validate ill-formed code is properly detected. |
| 16 | |
| 17 | // <format> |
| 18 | |
| 19 | // template<class... Args> |
| 20 | // size_t formatted_size(const locale& loc, |
| 21 | // format-string<Args...> fmt, const Args&... args); |
| 22 | // template<class... Args> |
| 23 | // size_t formatted_size(const locale& loc, |
| 24 | // wformat-string<Args...> fmt, const Args&... args); |
| 25 | |
| 26 | #include <format> |
| 27 | #include <locale> |
| 28 | |
| 29 | #include "test_macros.h" |
| 30 | |
| 31 | // clang-format off |
| 32 | |
| 33 | void f() { |
| 34 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), "{" ); // 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}} |
| 36 | |
| 37 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), "}" ); // 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}} |
| 39 | |
| 40 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), "{}" ); // 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}} |
| 42 | |
| 43 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), "{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}} |
| 45 | |
| 46 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), "{:-}" , "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}} |
| 48 | |
| 49 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), "{:#}" , "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}} |
| 51 | |
| 52 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), "{: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}} |
| 54 | |
| 55 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), "{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}} |
| 57 | |
| 58 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), "{:.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}} |
| 60 | |
| 61 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), "{: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}} |
| 63 | |
| 64 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 65 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), 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}} |
| 67 | |
| 68 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), 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}} |
| 70 | |
| 71 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), 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}} |
| 73 | |
| 74 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), 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}} |
| 76 | |
| 77 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), 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}} |
| 79 | |
| 80 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), 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}} |
| 82 | |
| 83 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), 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}} |
| 85 | |
| 86 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), 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}} |
| 88 | |
| 89 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), 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}} |
| 91 | |
| 92 | TEST_IGNORE_NODISCARD std::formatted_size(std::locale(), 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}} |
| 94 | #endif |
| 95 | } |
| 96 | |