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 // UNSUPPORTED: libcpp-has-no-incomplete-format
11 
12 // This test requires the dylib support introduced in D92214.
13 // XFAIL: use_system_cxx_lib && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14|15}}
14 
15 // <format>
16 
17 // class format_error;
18 
19 #include <format>
20 #include <type_traits>
21 #include <cstring>
22 #include <string>
23 #include <cassert>
24 
25 #include "test_macros.h"
26 
main(int,char **)27 int main(int, char**) {
28   static_assert(std::is_base_of_v<std::runtime_error, std::format_error>);
29   static_assert(std::is_polymorphic_v<std::format_error>);
30 
31   {
32     const char* msg = "format_error message c-string";
33     std::format_error e(msg);
34     assert(std::strcmp(e.what(), msg) == 0);
35     std::format_error e2(e);
36     assert(std::strcmp(e2.what(), msg) == 0);
37     e2 = e;
38     assert(std::strcmp(e2.what(), msg) == 0);
39   }
40   {
41     std::string msg("format_error message std::string");
42     std::format_error e(msg);
43     assert(e.what() == msg);
44     std::format_error e2(e);
45     assert(e2.what() == msg);
46     e2 = e;
47     assert(e2.what() == msg);
48   }
49 
50   return 0;
51 }
52