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 //===----------------------------------------------------------------------===// 7 8 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 9 // UNSUPPORTED: libcpp-has-no-incomplete-format 10 11 // TODO FMT Fix this test using GCC, it currently times out. 12 // UNSUPPORTED: gcc-12 13 14 // This test requires the dylib support introduced in D92214. 15 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{.+}} 16 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx11.{{.+}} 17 18 // <vector> 19 20 // template<class T, class charT> 21 // requires is-vector-bool-reference<T> 22 // struct formatter<T, charT> 23 24 // template<class ParseContext> 25 // constexpr typename ParseContext::iterator 26 // parse(ParseContext& ctx); 27 28 // Note this tests the basics of this function. It's tested in more detail in 29 // the format functions test. 30 31 #include <cassert> 32 #include <concepts> 33 #include <format> 34 #include <vector> 35 36 #include "test_format_context.h" 37 #include "test_macros.h" 38 #include "make_string.h" 39 40 #define SV(S) MAKE_STRING_VIEW(CharT, S) 41 42 template <class StringViewT> 43 constexpr void test_parse(StringViewT fmt) { 44 using CharT = typename StringViewT::value_type; 45 auto parse_ctx = std::basic_format_parse_context<CharT>(fmt); 46 std::formatter<std::vector<bool, std::allocator<bool>>::reference, CharT> formatter; 47 static_assert(std::semiregular<decltype(formatter)>); 48 49 std::same_as<typename StringViewT::iterator> auto it = formatter.parse(parse_ctx); 50 assert(it == fmt.end() - (!fmt.empty() && fmt.back() == '}')); 51 } 52 53 template <class CharT> 54 constexpr void test_fmt() { 55 test_parse(SV("")); 56 test_parse(SV("b")); 57 58 test_parse(SV("}")); 59 test_parse(SV("b}")); 60 } 61 62 constexpr bool test() { 63 test_fmt<char>(); 64 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 65 test_fmt<wchar_t>(); 66 #endif 67 68 return true; 69 } 70 71 int main(int, char**) { 72 test(); 73 static_assert(test()); 74 75 return 0; 76 } 77