Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / format / format.functions / format.verify.cpp
blob53b9b29fa72c6d010e19b9af1e845303d992e23f
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
5 //
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
13 // Basic test to validate ill-formed code is properly detected.
15 // <format>
17 // template<class... Args>
18 // string format(format-string<Args...> fmt, const Args&... args);
19 // template<class... Args>
20 // wstring format(wformat-string<Args...> fmt, const Args&... args);
22 #include <format>
24 #include "test_macros.h"
26 // clang-format off
28 void f() {
29 TEST_IGNORE_NODISCARD std::format("{"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
30 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
32 TEST_IGNORE_NODISCARD std::format("}"); // 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("{}"); // 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("{0}"); // 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("{:-}", "Forty-two"); // 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("{:#}", "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("{:L}", "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("{0:{0}}", "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("{:.42d}", "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("{:d}", "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 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
60 TEST_IGNORE_NODISCARD std::format(L"{"); // expected-error-re{{call to consteval function '{{.*}}' is not a constant expression}}
61 // expected-note@*:* {{non-constexpr function '__throw_format_error' cannot be used in a constant expression}}
63 TEST_IGNORE_NODISCARD std::format(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(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(L"{0}"); // 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(L"{:-}", L"Forty-two"); // 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(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(L"{: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(L"{0:{0}}", 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(L"{:.42d}", 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(L"{:d}", 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}}
89 #endif
92 struct tiny {
93 int bit : 1;
96 void P2418()
98 auto t = tiny{};
99 TEST_IGNORE_NODISCARD std::format("{}", t.bit); // expected-error{{non-const reference cannot bind to bit-field 'bit'}}
101 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
102 TEST_IGNORE_NODISCARD std::format(L"{}", t.bit); // expected-error{{non-const reference cannot bind to bit-field 'bit'}}
103 #endif