brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 22d74bb Raw
53 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// UNSUPPORTED: no-threads10 11// <future>12//13// class future_error14//15// const error_code& code() const noexcept;16 17#include <cassert>18#include <future>19#include <utility>20 21#include "test_macros.h"22 23int main(int, char**) {24  ASSERT_NOEXCEPT(std::declval<std::future_error const&>().code());25  ASSERT_SAME_TYPE(decltype(std::declval<std::future_error const&>().code()), std::error_code const&);26 27  // Before C++17, we can't construct std::future_error directly in a standards-conforming way28#if TEST_STD_VER >= 1729  {30    std::future_error const f(std::future_errc::broken_promise);31    std::error_code const& code = f.code();32    assert(code == std::make_error_code(std::future_errc::broken_promise));33  }34  {35    std::future_error const f(std::future_errc::future_already_retrieved);36    std::error_code const& code = f.code();37    assert(code == std::make_error_code(std::future_errc::future_already_retrieved));38  }39  {40    std::future_error const f(std::future_errc::promise_already_satisfied);41    std::error_code const& code = f.code();42    assert(code == std::make_error_code(std::future_errc::promise_already_satisfied));43  }44  {45    std::future_error const f(std::future_errc::no_state);46    std::error_code const& code = f.code();47    assert(code == std::make_error_code(std::future_errc::no_state));48  }49#endif50 51  return 0;52}53