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

source code of libcxx/test/std/thread/futures/futures.future_error/what.pass.cpp