| 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 | |
| 11 | // <format> |
| 12 | |
| 13 | // constexpr explicit |
| 14 | // basic_format_parse_context(basic_string_view<charT> fmt, |
| 15 | // size_t num_args = 0) noexcept |
| 16 | |
| 17 | #include <format> |
| 18 | |
| 19 | #include <cassert> |
| 20 | #include <string_view> |
| 21 | #include <type_traits> |
| 22 | |
| 23 | #include "test_macros.h" |
| 24 | |
| 25 | template <class CharT> |
| 26 | constexpr void test(const CharT* fmt) { |
| 27 | // Validate the constructor is explicit. |
| 28 | static_assert( |
| 29 | !std::is_convertible_v<std::basic_string_view<CharT>, |
| 30 | std::basic_format_parse_context<CharT> >); |
| 31 | static_assert( |
| 32 | !std::is_copy_constructible_v<std::basic_format_parse_context<CharT> >); |
| 33 | static_assert( |
| 34 | !std::is_copy_assignable_v<std::basic_format_parse_context<CharT> >); |
| 35 | // The move operations are implicitly deleted due to the |
| 36 | // deleted copy operations. |
| 37 | static_assert( |
| 38 | !std::is_move_constructible_v<std::basic_format_parse_context<CharT> >); |
| 39 | static_assert( |
| 40 | !std::is_move_assignable_v<std::basic_format_parse_context<CharT> >); |
| 41 | |
| 42 | ASSERT_NOEXCEPT(std::basic_format_parse_context{std::basic_string_view<CharT>{}}); |
| 43 | ASSERT_NOEXCEPT(std::basic_format_parse_context{std::basic_string_view<CharT>{}, 42}); |
| 44 | |
| 45 | { |
| 46 | std::basic_format_parse_context<CharT> context(fmt); |
| 47 | assert(std::to_address(context.begin()) == &fmt[0]); |
| 48 | assert(std::to_address(context.end()) == &fmt[3]); |
| 49 | } |
| 50 | { |
| 51 | std::basic_string_view view{fmt}; |
| 52 | std::basic_format_parse_context context(view); |
| 53 | assert(context.begin() == view.begin()); |
| 54 | assert(context.end() == view.end()); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | constexpr bool test() { |
| 59 | test(fmt: "abc" ); |
| 60 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 61 | test(fmt: L"abc" ); |
| 62 | #endif |
| 63 | #ifndef TEST_HAS_NO_CHAR8_T |
| 64 | test(fmt: u8"abc" ); |
| 65 | #endif |
| 66 | test(fmt: u"abc" ); |
| 67 | test(fmt: U"abc" ); |
| 68 | |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | int main(int, char**) { |
| 73 | test(); |
| 74 | static_assert(test()); |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |