| 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 | // class format_error; |
| 14 | |
| 15 | #include <format> |
| 16 | #include <type_traits> |
| 17 | #include <cstring> |
| 18 | #include <string> |
| 19 | #include <cassert> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | |
| 23 | int main(int, char**) { |
| 24 | static_assert(std::is_base_of_v<std::runtime_error, std::format_error>); |
| 25 | static_assert(std::is_polymorphic_v<std::format_error>); |
| 26 | |
| 27 | { |
| 28 | const char* msg = "format_error message c-string" ; |
| 29 | std::format_error e(msg); |
| 30 | assert(std::strcmp(e.what(), msg) == 0); |
| 31 | std::format_error e2(e); |
| 32 | assert(std::strcmp(e2.what(), msg) == 0); |
| 33 | e2 = e; |
| 34 | assert(std::strcmp(e2.what(), msg) == 0); |
| 35 | } |
| 36 | { |
| 37 | std::string msg("format_error message std::string" ); |
| 38 | std::format_error e(msg); |
| 39 | assert(e.what() == msg); |
| 40 | std::format_error e2(e); |
| 41 | assert(e2.what() == msg); |
| 42 | e2 = e; |
| 43 | assert(e2.what() == msg); |
| 44 | } |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |