xref: /llvm-project/libcxx/test/libcxx/utilities/expected/expected.expected/assert.error.pass.cpp (revision 58780b811c23df3d928d8452ee21c862dde754a2)
1e356f681SHui Xie //===----------------------------------------------------------------------===//
2e356f681SHui Xie //
3e356f681SHui Xie // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e356f681SHui Xie // See https://llvm.org/LICENSE.txt for license information.
5e356f681SHui Xie // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6e356f681SHui Xie //
7e356f681SHui Xie //===----------------------------------------------------------------------===//
8e356f681SHui Xie 
9e356f681SHui Xie // REQUIRES: has-unix-headers
10e356f681SHui Xie // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
1164d413efSKonstantin Varlamov // UNSUPPORTED: libcpp-hardening-mode=none
12*58780b81SKonstantin Varlamov // XFAIL: libcpp-hardening-mode=debug && availability-verbose_abort-missing
13e356f681SHui Xie 
14e356f681SHui Xie // constexpr const E& error() const & noexcept;
15e356f681SHui Xie // constexpr E& error() & noexcept;
16e356f681SHui Xie // constexpr E&& error() && noexcept;
17e356f681SHui Xie // constexpr const E&& error() const && noexcept;
18e356f681SHui Xie //
19e356f681SHui Xie // Preconditions: has_value() is false.
20e356f681SHui Xie 
21e356f681SHui Xie #include <expected>
22e356f681SHui Xie #include <utility>
23e356f681SHui Xie 
24e356f681SHui Xie #include "check_assertion.h"
25e356f681SHui Xie 
main(int,char **)26e356f681SHui Xie int main(int, char**) {
27e356f681SHui Xie   std::expected<int, int> e{std::in_place, 5};
28e356f681SHui Xie   TEST_LIBCPP_ASSERT_FAILURE(e.error(), "expected::error requires the expected to contain an error");
29e356f681SHui Xie   TEST_LIBCPP_ASSERT_FAILURE(std::as_const(e).error(), "expected::error requires the expected to contain an error");
30e356f681SHui Xie   TEST_LIBCPP_ASSERT_FAILURE(std::move(e).error(), "expected::error requires the expected to contain an error");
31e356f681SHui Xie   TEST_LIBCPP_ASSERT_FAILURE(std::move(std::as_const(e)).error(), "expected::error requires the expected to contain an error");
32e356f681SHui Xie 
33e356f681SHui Xie   return 0;
34e356f681SHui Xie }
35