| 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 void value() const &; |
| 11 |
// constexpr void value() &&; |
| 12 |
|
| 13 |
#include <cassert> |
| 14 |
#include <concepts> |
| 15 |
#include <expected> |
| 16 |
#include <type_traits> |
| 17 |
#include <utility> |
| 18 |
|
| 19 |
#include "MoveOnly.h" |
| 20 |
#include "test_macros.h" |
| 21 |
|
| 22 |
constexpr bool test() { |
| 23 |
// const & |
| 24 |
{ |
| 25 |
const std::expected<void, int> e; |
| 26 |
e.value(); |
| 27 |
static_assert(std::is_same_v<decltype(e.value()), void>); |
| 28 |
} |
| 29 |
|
| 30 |
// & |
| 31 |
{ |
| 32 |
std::expected<void, int> e; |
| 33 |
e.value(); |
| 34 |
static_assert(std::is_same_v<decltype(e.value()), void>); |
| 35 |
} |
| 36 |
|
| 37 |
// && |
| 38 |
{ |
| 39 |
std::expected<void, int> e; |
| 40 |
std::move(e).value(); |
| 41 |
static_assert(std::is_same_v<decltype(std::move(e).value()), void>); |
| 42 |
} |
| 43 |
|
| 44 |
// const && |
| 45 |
{ |
| 46 |
const std::expected<void, int> e; |
| 47 |
std::move(e).value(); |
| 48 |
static_assert(std::is_same_v<decltype(std::move(e).value()), void>); |
| 49 |
} |
| 50 |
|
| 51 |
return true; |
| 52 |
} |
| 53 |
|
| 54 |
void testException() { |
| 55 |
#ifndef TEST_HAS_NO_EXCEPTIONS |
| 56 |
|
| 57 |
// int |
| 58 |
{ |
| 59 |
const std::expected<void, int> e(std::unexpect, 5); |
| 60 |
try { |
| 61 |
e.value(); |
| 62 |
assert(false); |
| 63 |
} catch (const std::bad_expected_access<int>& ex) { |
| 64 |
assert(ex.error() == 5); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
#endif // TEST_HAS_NO_EXCEPTIONS |
| 69 |
} |
| 70 |
|
| 71 |
int main(int, char**) { |
| 72 |
test(); |
| 73 |
static_assert(test()); |
| 74 |
testException(); |
| 75 |
return 0; |
| 76 |
} |