Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / format / format.range / format.range.fmtdef / parse.pass.cpp
blob9f9b4d4545a8921040c4517a99687667af6fa1e8
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, c++20
10 // UNSUPPORTED: GCC-ALWAYS_INLINE-FIXME
12 // <format>
14 // template<ranges::input_range R, class charT>
15 // struct range-default-formatter<range_format::sequence, R, charT>
17 // template<class ParseContext>
18 // constexpr typename ParseContext::iterator
19 // parse(ParseContext& ctx);
21 #include <array>
22 #include <cassert>
23 #include <concepts>
24 #include <format>
26 #include "test_format_context.h"
27 #include "test_macros.h"
28 #include "make_string.h"
30 #define SV(S) MAKE_STRING_VIEW(CharT, S)
32 template <class StringViewT>
33 constexpr void test_parse(StringViewT fmt, std::size_t offset) {
34 using CharT = typename StringViewT::value_type;
35 auto parse_ctx = std::basic_format_parse_context<CharT>(fmt);
36 std::formatter<std::array<int, 2>, CharT> formatter;
37 static_assert(std::semiregular<decltype(formatter)>);
39 std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx);
40 assert(it == fmt.end() - offset);
43 template <class CharT>
44 constexpr void test_fmt() {
45 test_parse(SV(""), 0);
46 test_parse(SV(":5"), 0);
48 test_parse(SV("}"), 1);
49 test_parse(SV(":5}"), 1);
52 constexpr bool test() {
53 test_fmt<char>();
54 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
55 test_fmt<wchar_t>();
56 #endif
58 return true;
61 int main(int, char**) {
62 test();
63 static_assert(test());
65 return 0;