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 // 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.
14 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{9|10|11}}
16 // VC Runtime's std::exception::what() method is not marked as noexcept, so
18 // UNSUPPORTED: target=x86_64-pc-windows-msvc
24 // const char* what() const noexcept;
28 #include <string_view>
31 #include "test_macros.h"
33 int 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*);
37 // Before C++17, we can't construct std::future_error directly in a standards-conforming way
38 #if TEST_STD_VER >= 17
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."});
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."});
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."});
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."});