1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-threads
11 // VC Runtime's std::exception::what() method is not marked as noexcept, so
13 // UNSUPPORTED: target=x86_64-pc-windows-msvc
19 // const char* what() const noexcept;
23 #include <string_view>
26 #include "test_macros.h"
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*);
32 // Before C++17, we can't construct std::future_error directly in a standards-conforming way
33 #if TEST_STD_VER >= 17
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."});
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."});
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."});
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."});