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