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: no-threads |
10 | |
11 | // VC Runtime's std::exception::what() method is not marked as noexcept, so |
12 | // this fails. |
13 | // UNSUPPORTED: target=x86_64-pc-windows-msvc |
14 | |
15 | // <future> |
16 | // |
17 | // class future_error |
18 | // |
19 | // const char* what() const noexcept; |
20 | |
21 | #include <cassert> |
22 | #include <future> |
23 | #include <string_view> |
24 | #include <utility> |
25 | |
26 | #include "test_macros.h" |
27 | |
28 | int main(int, char**) { |
29 | ASSERT_NOEXCEPT(std::declval<std::future_error const&>().what()); |
30 | ASSERT_SAME_TYPE(decltype(std::declval<std::future_error const&>().what()), char const*); |
31 | |
32 | // Before C++17, we can't construct std::future_error directly in a standards-conforming way |
33 | #if TEST_STD_VER >= 17 |
34 | { |
35 | std::future_error const f(std::future_errc::broken_promise); |
36 | [[maybe_unused]] char const* what = f.what(); |
37 | LIBCPP_ASSERT(what == std::string_view{"The associated promise has been destructed prior " |
38 | "to the associated state becoming ready." }); |
39 | } |
40 | { |
41 | std::future_error f(std::future_errc::future_already_retrieved); |
42 | [[maybe_unused]] char const* what = f.what(); |
43 | LIBCPP_ASSERT(what == std::string_view{"The future has already been retrieved from " |
44 | "the promise or packaged_task." }); |
45 | } |
46 | { |
47 | std::future_error f(std::future_errc::promise_already_satisfied); |
48 | [[maybe_unused]] char const* what = f.what(); |
49 | LIBCPP_ASSERT(what == std::string_view{"The state of the promise has already been set." }); |
50 | } |
51 | { |
52 | std::future_error f(std::future_errc::no_state); |
53 | [[maybe_unused]] char const* what = f.what(); |
54 | LIBCPP_ASSERT(what == std::string_view{"Operation not permitted on an object without " |
55 | "an associated state." }); |
56 | } |
57 | #endif |
58 | |
59 | return 0; |
60 | } |
61 | |