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
9 // UNSUPPORTED: libcpp-no-concepts
10 // UNSUPPORTED: no-exceptions
11 // UNSUPPORTED: libcpp-has-no-incomplete-format
12 
13 // This test requires the dylib support introduced in D92214.
14 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14|15}}
15 
16 // <format>
17 
18 // constexpr size_t next_arg_id();
19 
20 #include <format>
21 
22 #include <cassert>
23 #include <string_view>
24 
25 #include "test_macros.h"
26 
test()27 constexpr bool test() {
28   std::format_parse_context context("");
29   for (size_t i = 0; i < 10; ++i)
30     assert(i == context.next_arg_id());
31 
32   return true;
33 }
34 
test_exception()35 void test_exception() {
36   std::format_parse_context context("", 1);
37   context.check_arg_id(0);
38 
39   try {
40     context.next_arg_id();
41     assert(false);
42   } catch (const std::format_error& e) {
43     LIBCPP_ASSERT(strcmp(e.what(), "Using automatic argument numbering in manual "
44                                    "argument numbering mode") == 0);
45     return;
46   }
47   assert(false);
48 }
49 
main(int,char **)50 int main(int, char**) {
51   test();
52   test_exception();
53   static_assert(test());
54 
55   return 0;
56 }
57