1//===----------------------------------------------------------------------===//
2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3// See https://llvm.org/LICENSE.txt for license information.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7
8// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9
10// constexpr const E& error() const & noexcept;
11
12#include <cassert>
13#include <concepts>
14#include <expected>
15#include <utility>
16
17template <class T>
18concept ErrorNoexcept =
19 requires(const T& t) {
20 { t.error() } noexcept;
21 };
22
23static_assert(!ErrorNoexcept<int>);
24static_assert(ErrorNoexcept<std::unexpected<int>>);
25
26constexpr bool test() {
27 const std::unexpected<int> unex(5);
28 decltype(auto) i = unex.error();
29 static_assert(std::same_as<decltype(i), const int&>);
30 assert(i == 5);
31 return true;
32}
33
34int main(int, char**) {
35 test();
36 static_assert(test());
37 return 0;
38}
39

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