[llvm][llvm-readobj] Add NT_ARM_GCS Linux core note type (#117545)
[llvm-project.git] / libcxx / test / std / utilities / format / format.functions / format.verify.cpp
blob9e1f86b474b8687ccf84ee894ffbc664d6ddffab
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
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... Args>
19 // string format(format-string<Args...> fmt, const Args&... args);
20 // template<class... Args>
21 // wstring format(wformat-string<Args...> fmt, const Args&... args);
23 #include <format>
25 #include "test_macros.h"
27 // clang-format off
29 void f() {
30 TEST_IGNORE_NODISCARD std::format("{"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
31 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
33 TEST_IGNORE_NODISCARD std::format("}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
34 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
36 TEST_IGNORE_NODISCARD std::format("{}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
37 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
39 TEST_IGNORE_NODISCARD std::format("{0}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
40 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
42 TEST_IGNORE_NODISCARD std::format("{:-}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
43 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
45 TEST_IGNORE_NODISCARD std::format("{:#}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
46 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
48 TEST_IGNORE_NODISCARD std::format("{:L}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
49 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
51 TEST_IGNORE_NODISCARD std::format("{0:{0}}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
52 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
54 TEST_IGNORE_NODISCARD std::format("{:.42d}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
55 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
57 TEST_IGNORE_NODISCARD std::format("{:d}", "Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
58 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
60 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
61 TEST_IGNORE_NODISCARD std::format(L"{"); // 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 TEST_IGNORE_NODISCARD std::format(L"}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
65 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
67 TEST_IGNORE_NODISCARD std::format(L"{}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
68 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
70 TEST_IGNORE_NODISCARD std::format(L"{0}"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
71 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
73 TEST_IGNORE_NODISCARD std::format(L"{:-}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
74 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
76 TEST_IGNORE_NODISCARD std::format(L"{:#}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
77 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
79 TEST_IGNORE_NODISCARD std::format(L"{:L}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
80 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
82 TEST_IGNORE_NODISCARD std::format(L"{0:{0}}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
83 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
85 TEST_IGNORE_NODISCARD std::format(L"{:.42d}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
86 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
88 TEST_IGNORE_NODISCARD std::format(L"{:d}", L"Forty-two"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
89 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
90 #endif
93 struct tiny {
94 int bit : 1;
97 void P2418()
99 auto t = tiny{};
100 TEST_IGNORE_NODISCARD std::format("{}", t.bit); // expected-error{{non-const reference cannot bind to bit-field 'bit'}}
102 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
103 TEST_IGNORE_NODISCARD std::format(L"{}", t.bit); // expected-error{{non-const reference cannot bind to bit-field 'bit'}}
104 #endif