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: c++03, c++11, c++14, c++17, c++20
10
11// constexpr E&& error() && noexcept;
12
13#include <cassert>
14#include <concepts>
15#include <expected>
16#include <utility>
17
18template <class T>
19concept ErrorNoexcept =
20 requires(T&& t) {
21 { std::move(t).error() } noexcept;
22 };
23
24static_assert(!ErrorNoexcept<int>);
25static_assert(ErrorNoexcept<std::unexpected<int>>);
26
27constexpr bool test() {
28 std::unexpected<int> unex(5);
29 decltype(auto) i = std::move(unex).error();
30 static_assert(std::same_as<decltype(i), int&&>);
31 assert(i == 5);
32 return true;
33}
34
35int main(int, char**) {
36 test();
37 static_assert(test());
38 return 0;
39}
40

source code of libcxx/test/std/utilities/expected/expected.unexpected/observer/error.ref_ref.pass.cpp