[libc++][expected] Applied [[nodiscard]] (#170245)

[[nodiscard]] should be applied to functions where discarding the return
value is most likely a correctness issue.

- https://libcxx.llvm.org/CodingGuidelines.html
- https://wg21.link/expected.bad.void
- https://wg21.link/expected.bad
- https://wg21.link/expected.expected
- https://wg21.link/expected.void
- https://wg21.link/expected.unexpected

It was already discussed not to mark the type `std::expected` as
`[[nodiscard]]` see:
https://github.com/llvm/llvm-project/pull/139651
https://github.com/llvm/llvm-project/pull/130820
Also:
https://github.com/llvm/llvm-project/pull/154943
This commit is contained in:
Hristo Hristov 2025-12-14 19:11:16 +02:00 committed by GitHub
parent 8f93365b19
commit 9975cb166e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 312 additions and 130 deletions

View file

@ -43,9 +43,11 @@ protected:
public:
# if _LIBCPP_AVAILABILITY_HAS_BAD_EXPECTED_ACCESS_KEY_FUNCTION
const char* what() const noexcept override;
[[nodiscard]] const char* what() const noexcept override;
# else
_LIBCPP_HIDE_FROM_ABI_VIRTUAL const char* what() const noexcept override { return "bad access to std::expected"; }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI_VIRTUAL const char* what() const noexcept override {
return "bad access to std::expected";
}
# endif
};
_LIBCPP_DIAGNOSTIC_POP
@ -55,10 +57,10 @@ class bad_expected_access : public bad_expected_access<void> {
public:
_LIBCPP_HIDE_FROM_ABI explicit bad_expected_access(_Err __e) : __unex_(std::move(__e)) {}
_LIBCPP_HIDE_FROM_ABI _Err& error() & noexcept { return __unex_; }
_LIBCPP_HIDE_FROM_ABI const _Err& error() const& noexcept { return __unex_; }
_LIBCPP_HIDE_FROM_ABI _Err&& error() && noexcept { return std::move(__unex_); }
_LIBCPP_HIDE_FROM_ABI const _Err&& error() const&& noexcept { return std::move(__unex_); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Err& error() & noexcept { return __unex_; }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const _Err& error() const& noexcept { return __unex_; }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI _Err&& error() && noexcept { return std::move(__unex_); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI const _Err&& error() const&& noexcept { return std::move(__unex_); }
private:
_Err __unex_;

View file

@ -798,25 +798,25 @@ public:
return std::addressof(this->__val());
}
_LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator*() const& noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& operator*() const& noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
this->__has_val(), "expected::operator* requires the expected to contain a value");
return this->__val();
}
_LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator*() & noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator*() & noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
this->__has_val(), "expected::operator* requires the expected to contain a value");
return this->__val();
}
_LIBCPP_HIDE_FROM_ABI constexpr const _Tp&& operator*() const&& noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&& operator*() const&& noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
this->__has_val(), "expected::operator* requires the expected to contain a value");
return std::move(this->__val());
}
_LIBCPP_HIDE_FROM_ABI constexpr _Tp&& operator*() && noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp&& operator*() && noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
this->__has_val(), "expected::operator* requires the expected to contain a value");
return std::move(this->__val());
@ -824,9 +824,9 @@ public:
_LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return this->__has_val(); }
_LIBCPP_HIDE_FROM_ABI constexpr bool has_value() const noexcept { return this->__has_val(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_value() const noexcept { return this->__has_val(); }
_LIBCPP_HIDE_FROM_ABI constexpr const _Tp& value() const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp& value() const& {
static_assert(is_copy_constructible_v<_Err>, "error_type has to be copy constructible");
if (!this->__has_val()) {
std::__throw_bad_expected_access<_Err>(std::as_const(error()));
@ -834,7 +834,7 @@ public:
return this->__val();
}
_LIBCPP_HIDE_FROM_ABI constexpr _Tp& value() & {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp& value() & {
static_assert(is_copy_constructible_v<_Err>, "error_type has to be copy constructible");
if (!this->__has_val()) {
std::__throw_bad_expected_access<_Err>(std::as_const(error()));
@ -842,7 +842,7 @@ public:
return this->__val();
}
_LIBCPP_HIDE_FROM_ABI constexpr const _Tp&& value() const&& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Tp&& value() const&& {
static_assert(is_copy_constructible_v<_Err> && is_constructible_v<_Err, decltype(std::move(error()))>,
"error_type has to be both copy constructible and constructible from decltype(std::move(error()))");
if (!this->__has_val()) {
@ -851,7 +851,7 @@ public:
return std::move(this->__val());
}
_LIBCPP_HIDE_FROM_ABI constexpr _Tp&& value() && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp&& value() && {
static_assert(is_copy_constructible_v<_Err> && is_constructible_v<_Err, decltype(std::move(error()))>,
"error_type has to be both copy constructible and constructible from decltype(std::move(error()))");
if (!this->__has_val()) {
@ -860,46 +860,46 @@ public:
return std::move(this->__val());
}
_LIBCPP_HIDE_FROM_ABI constexpr const _Err& error() const& noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Err& error() const& noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
!this->__has_val(), "expected::error requires the expected to contain an error");
return this->__unex();
}
_LIBCPP_HIDE_FROM_ABI constexpr _Err& error() & noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Err& error() & noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
!this->__has_val(), "expected::error requires the expected to contain an error");
return this->__unex();
}
_LIBCPP_HIDE_FROM_ABI constexpr const _Err&& error() const&& noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Err&& error() const&& noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
!this->__has_val(), "expected::error requires the expected to contain an error");
return std::move(this->__unex());
}
_LIBCPP_HIDE_FROM_ABI constexpr _Err&& error() && noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Err&& error() && noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
!this->__has_val(), "expected::error requires the expected to contain an error");
return std::move(this->__unex());
}
template <class _Up = remove_cv_t<_Tp>>
_LIBCPP_HIDE_FROM_ABI constexpr _Tp value_or(_Up&& __v) const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp value_or(_Up&& __v) const& {
static_assert(is_copy_constructible_v<_Tp>, "value_type has to be copy constructible");
static_assert(is_convertible_v<_Up, _Tp>, "argument has to be convertible to value_type");
return this->__has_val() ? this->__val() : static_cast<_Tp>(std::forward<_Up>(__v));
}
template <class _Up = remove_cv_t<_Tp>>
_LIBCPP_HIDE_FROM_ABI constexpr _Tp value_or(_Up&& __v) && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp value_or(_Up&& __v) && {
static_assert(is_move_constructible_v<_Tp>, "value_type has to be move constructible");
static_assert(is_convertible_v<_Up, _Tp>, "argument has to be convertible to value_type");
return this->__has_val() ? std::move(this->__val()) : static_cast<_Tp>(std::forward<_Up>(__v));
}
template <class _Up = _Err>
_LIBCPP_HIDE_FROM_ABI constexpr _Err error_or(_Up&& __error) const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Err error_or(_Up&& __error) const& {
static_assert(is_copy_constructible_v<_Err>, "error_type has to be copy constructible");
static_assert(is_convertible_v<_Up, _Err>, "argument has to be convertible to error_type");
if (has_value())
@ -908,7 +908,7 @@ public:
}
template <class _Up = _Err>
_LIBCPP_HIDE_FROM_ABI constexpr _Err error_or(_Up&& __error) && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Err error_or(_Up&& __error) && {
static_assert(is_move_constructible_v<_Err>, "error_type has to be move constructible");
static_assert(is_convertible_v<_Up, _Err>, "argument has to be convertible to error_type");
if (has_value())
@ -919,7 +919,7 @@ public:
// [expected.void.monadic], monadic
template <class _Func>
requires is_constructible_v<_Err, _Err&>
_LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) & {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) & {
using _Up = remove_cvref_t<invoke_result_t<_Func, _Tp&>>;
static_assert(__is_std_expected<_Up>::value, "The result of f(value()) must be a specialization of std::expected");
static_assert(is_same_v<typename _Up::error_type, _Err>,
@ -932,7 +932,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, const _Err&>
_LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const& {
using _Up = remove_cvref_t<invoke_result_t<_Func, const _Tp&>>;
static_assert(__is_std_expected<_Up>::value, "The result of f(value()) must be a specialization of std::expected");
static_assert(is_same_v<typename _Up::error_type, _Err>,
@ -945,7 +945,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, _Err&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) && {
using _Up = remove_cvref_t<invoke_result_t<_Func, _Tp&&>>;
static_assert(
__is_std_expected<_Up>::value, "The result of f(std::move(value())) must be a specialization of std::expected");
@ -959,7 +959,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, const _Err&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const&& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const&& {
using _Up = remove_cvref_t<invoke_result_t<_Func, const _Tp&&>>;
static_assert(
__is_std_expected<_Up>::value, "The result of f(std::move(value())) must be a specialization of std::expected");
@ -973,7 +973,7 @@ public:
template <class _Func>
requires is_constructible_v<_Tp, _Tp&>
_LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) & {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) & {
using _Gp = remove_cvref_t<invoke_result_t<_Func, _Err&>>;
static_assert(__is_std_expected<_Gp>::value, "The result of f(error()) must be a specialization of std::expected");
static_assert(is_same_v<typename _Gp::value_type, _Tp>,
@ -986,7 +986,7 @@ public:
template <class _Func>
requires is_constructible_v<_Tp, const _Tp&>
_LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) const& {
using _Gp = remove_cvref_t<invoke_result_t<_Func, const _Err&>>;
static_assert(__is_std_expected<_Gp>::value, "The result of f(error()) must be a specialization of std::expected");
static_assert(is_same_v<typename _Gp::value_type, _Tp>,
@ -999,7 +999,7 @@ public:
template <class _Func>
requires is_constructible_v<_Tp, _Tp&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) && {
using _Gp = remove_cvref_t<invoke_result_t<_Func, _Err&&>>;
static_assert(
__is_std_expected<_Gp>::value, "The result of f(std::move(error())) must be a specialization of std::expected");
@ -1013,7 +1013,7 @@ public:
template <class _Func>
requires is_constructible_v<_Tp, const _Tp&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) const&& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) const&& {
using _Gp = remove_cvref_t<invoke_result_t<_Func, const _Err&&>>;
static_assert(
__is_std_expected<_Gp>::value, "The result of f(std::move(error())) must be a specialization of std::expected");
@ -1027,7 +1027,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, _Err&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) & {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) & {
using _Up = remove_cv_t<invoke_result_t<_Func, _Tp&>>;
if (!has_value()) {
return expected<_Up, _Err>(unexpect, error());
@ -1043,7 +1043,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, const _Err&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) const& {
using _Up = remove_cv_t<invoke_result_t<_Func, const _Tp&>>;
if (!has_value()) {
return expected<_Up, _Err>(unexpect, error());
@ -1059,7 +1059,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, _Err&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) && {
using _Up = remove_cv_t<invoke_result_t<_Func, _Tp&&>>;
if (!has_value()) {
return expected<_Up, _Err>(unexpect, std::move(error()));
@ -1075,7 +1075,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, const _Err&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) const&& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) const&& {
using _Up = remove_cv_t<invoke_result_t<_Func, const _Tp&&>>;
if (!has_value()) {
return expected<_Up, _Err>(unexpect, std::move(error()));
@ -1091,7 +1091,7 @@ public:
template <class _Func>
requires is_constructible_v<_Tp, _Tp&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) & {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) & {
using _Gp = remove_cv_t<invoke_result_t<_Func, _Err&>>;
static_assert(__valid_std_unexpected<_Gp>::value,
"The result of f(error()) must be a valid template argument for unexpected");
@ -1103,7 +1103,7 @@ public:
template <class _Func>
requires is_constructible_v<_Tp, const _Tp&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) const& {
using _Gp = remove_cv_t<invoke_result_t<_Func, const _Err&>>;
static_assert(__valid_std_unexpected<_Gp>::value,
"The result of f(error()) must be a valid template argument for unexpected");
@ -1115,7 +1115,7 @@ public:
template <class _Func>
requires is_constructible_v<_Tp, _Tp&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) && {
using _Gp = remove_cv_t<invoke_result_t<_Func, _Err&&>>;
static_assert(__valid_std_unexpected<_Gp>::value,
"The result of f(std::move(error())) must be a valid template argument for unexpected");
@ -1128,7 +1128,7 @@ public:
template <class _Func>
requires is_constructible_v<_Tp, const _Tp&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) const&& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) const&& {
using _Gp = remove_cv_t<invoke_result_t<_Func, const _Err&&>>;
static_assert(__valid_std_unexpected<_Gp>::value,
"The result of f(std::move(error())) must be a valid template argument for unexpected");
@ -1595,7 +1595,7 @@ public:
// [expected.void.obs], observers
_LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return this->__has_val(); }
_LIBCPP_HIDE_FROM_ABI constexpr bool has_value() const noexcept { return this->__has_val(); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool has_value() const noexcept { return this->__has_val(); }
_LIBCPP_HIDE_FROM_ABI constexpr void operator*() const noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
@ -1616,32 +1616,32 @@ public:
}
}
_LIBCPP_HIDE_FROM_ABI constexpr const _Err& error() const& noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Err& error() const& noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
!this->__has_val(), "expected::error requires the expected to contain an error");
return this->__unex();
}
_LIBCPP_HIDE_FROM_ABI constexpr _Err& error() & noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Err& error() & noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
!this->__has_val(), "expected::error requires the expected to contain an error");
return this->__unex();
}
_LIBCPP_HIDE_FROM_ABI constexpr const _Err&& error() const&& noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Err&& error() const&& noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
!this->__has_val(), "expected::error requires the expected to contain an error");
return std::move(this->__unex());
}
_LIBCPP_HIDE_FROM_ABI constexpr _Err&& error() && noexcept {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Err&& error() && noexcept {
_LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(
!this->__has_val(), "expected::error requires the expected to contain an error");
return std::move(this->__unex());
}
template <class _Up = _Err>
_LIBCPP_HIDE_FROM_ABI constexpr _Err error_or(_Up&& __error) const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Err error_or(_Up&& __error) const& {
static_assert(is_copy_constructible_v<_Err>, "error_type has to be copy constructible");
static_assert(is_convertible_v<_Up, _Err>, "argument has to be convertible to error_type");
if (has_value()) {
@ -1651,7 +1651,7 @@ public:
}
template <class _Up = _Err>
_LIBCPP_HIDE_FROM_ABI constexpr _Err error_or(_Up&& __error) && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Err error_or(_Up&& __error) && {
static_assert(is_move_constructible_v<_Err>, "error_type has to be move constructible");
static_assert(is_convertible_v<_Up, _Err>, "argument has to be convertible to error_type");
if (has_value()) {
@ -1663,7 +1663,7 @@ public:
// [expected.void.monadic], monadic
template <class _Func>
requires is_constructible_v<_Err, _Err&>
_LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) & {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) & {
using _Up = remove_cvref_t<invoke_result_t<_Func>>;
static_assert(__is_std_expected<_Up>::value, "The result of f() must be a specialization of std::expected");
static_assert(
@ -1676,7 +1676,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, const _Err&>
_LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const& {
using _Up = remove_cvref_t<invoke_result_t<_Func>>;
static_assert(__is_std_expected<_Up>::value, "The result of f() must be a specialization of std::expected");
static_assert(
@ -1689,7 +1689,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, _Err&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) && {
using _Up = remove_cvref_t<invoke_result_t<_Func>>;
static_assert(__is_std_expected<_Up>::value, "The result of f() must be a specialization of std::expected");
static_assert(
@ -1702,7 +1702,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, const _Err&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const&& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto and_then(_Func&& __f) const&& {
using _Up = remove_cvref_t<invoke_result_t<_Func>>;
static_assert(__is_std_expected<_Up>::value, "The result of f() must be a specialization of std::expected");
static_assert(
@ -1714,7 +1714,7 @@ public:
}
template <class _Func>
_LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) & {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) & {
using _Gp = remove_cvref_t<invoke_result_t<_Func, _Err&>>;
static_assert(__is_std_expected<_Gp>::value, "The result of f(error()) must be a specialization of std::expected");
static_assert(is_same_v<typename _Gp::value_type, _Tp>,
@ -1726,7 +1726,7 @@ public:
}
template <class _Func>
_LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) const& {
using _Gp = remove_cvref_t<invoke_result_t<_Func, const _Err&>>;
static_assert(__is_std_expected<_Gp>::value, "The result of f(error()) must be a specialization of std::expected");
static_assert(is_same_v<typename _Gp::value_type, _Tp>,
@ -1738,7 +1738,7 @@ public:
}
template <class _Func>
_LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) && {
using _Gp = remove_cvref_t<invoke_result_t<_Func, _Err&&>>;
static_assert(
__is_std_expected<_Gp>::value, "The result of f(std::move(error())) must be a specialization of std::expected");
@ -1751,7 +1751,7 @@ public:
}
template <class _Func>
_LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) const&& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto or_else(_Func&& __f) const&& {
using _Gp = remove_cvref_t<invoke_result_t<_Func, const _Err&&>>;
static_assert(
__is_std_expected<_Gp>::value, "The result of f(std::move(error())) must be a specialization of std::expected");
@ -1765,7 +1765,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, _Err&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) & {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) & {
using _Up = remove_cv_t<invoke_result_t<_Func>>;
if (!has_value()) {
return expected<_Up, _Err>(unexpect, error());
@ -1780,7 +1780,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, const _Err&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) const& {
using _Up = remove_cv_t<invoke_result_t<_Func>>;
if (!has_value()) {
return expected<_Up, _Err>(unexpect, error());
@ -1795,7 +1795,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, _Err&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) && {
using _Up = remove_cv_t<invoke_result_t<_Func>>;
if (!has_value()) {
return expected<_Up, _Err>(unexpect, std::move(error()));
@ -1810,7 +1810,7 @@ public:
template <class _Func>
requires is_constructible_v<_Err, const _Err&&>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) const&& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform(_Func&& __f) const&& {
using _Up = remove_cv_t<invoke_result_t<_Func>>;
if (!has_value()) {
return expected<_Up, _Err>(unexpect, std::move(error()));
@ -1824,7 +1824,7 @@ public:
}
template <class _Func>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) & {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) & {
using _Gp = remove_cv_t<invoke_result_t<_Func, _Err&>>;
static_assert(__valid_std_unexpected<_Gp>::value,
"The result of f(error()) must be a valid template argument for unexpected");
@ -1835,7 +1835,7 @@ public:
}
template <class _Func>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) const& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) const& {
using _Gp = remove_cv_t<invoke_result_t<_Func, const _Err&>>;
static_assert(__valid_std_unexpected<_Gp>::value,
"The result of f(error()) must be a valid template argument for unexpected");
@ -1846,7 +1846,7 @@ public:
}
template <class _Func>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) && {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) && {
using _Gp = remove_cv_t<invoke_result_t<_Func, _Err&&>>;
static_assert(__valid_std_unexpected<_Gp>::value,
"The result of f(std::move(error())) must be a valid template argument for unexpected");
@ -1858,7 +1858,7 @@ public:
}
template <class _Func>
_LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) const&& {
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto transform_error(_Func&& __f) const&& {
using _Gp = remove_cv_t<invoke_result_t<_Func, const _Err&&>>;
static_assert(__valid_std_unexpected<_Gp>::value,
"The result of f(std::move(error())) must be a valid template argument for unexpected");

View file

@ -89,10 +89,10 @@ public:
_LIBCPP_HIDE_FROM_ABI constexpr unexpected& operator=(const unexpected&) = default;
_LIBCPP_HIDE_FROM_ABI constexpr unexpected& operator=(unexpected&&) = default;
_LIBCPP_HIDE_FROM_ABI constexpr const _Err& error() const& noexcept { return __unex_; }
_LIBCPP_HIDE_FROM_ABI constexpr _Err& error() & noexcept { return __unex_; }
_LIBCPP_HIDE_FROM_ABI constexpr const _Err&& error() const&& noexcept { return std::move(__unex_); }
_LIBCPP_HIDE_FROM_ABI constexpr _Err&& error() && noexcept { return std::move(__unex_); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Err& error() const& noexcept { return __unex_; }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Err& error() & noexcept { return __unex_; }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr const _Err&& error() const&& noexcept { return std::move(__unex_); }
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Err&& error() && noexcept { return std::move(__unex_); }
_LIBCPP_HIDE_FROM_ABI constexpr void swap(unexpected& __other) noexcept(is_nothrow_swappable_v<_Err>) {
static_assert(is_swappable_v<_Err>, "unexpected::swap requires is_swappable_v<E> to be true");

View file

@ -51,7 +51,7 @@ void test() {
// U is not a specialization of std::expected
{
std::expected<int, int> f1(1);
f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &)>' requested here}}
(void)f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -61,7 +61,7 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
std::expected<int, int> f1(1);
f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &)>' requested here}}
(void)f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must have the same error_type as this expected}}
}
}
@ -71,7 +71,7 @@ void test() {
// U is not a specialization of std::expected
{
const std::expected<int, int> f1(1);
f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &)>' requested here}}
(void)f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -81,7 +81,7 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
const std::expected<int, int> f1(1);
f1.and_then(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &)>' requested here}}
(void)f1.and_then(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(value()) must have the same error_type as this expected}}
}
@ -92,7 +92,7 @@ void test() {
// U is not a specialization of std::expected
{
std::expected<int, int> f1(1);
std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &&)>' requested here}}
(void)std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -102,7 +102,7 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
std::expected<int, int> f1(1);
std::move(f1).and_then(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &&)>' requested here}}
(void)std::move(f1).and_then(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must have the same error_type as this expected}}
}
}
@ -112,7 +112,7 @@ void test() {
// U is not a specialization of std::expected
{
const std::expected<int, int> f1(1);
std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &&)>' requested here}}
(void)std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<int (&)(const int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -122,7 +122,7 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
const std::expected<int, int> f1(1);
std::move(f1).and_then(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &&)>' requested here}}
(void)std::move(f1).and_then(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::and_then<std::expected<int, NotSameAsInt> (&)(const int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(value())) must have the same error_type as this expected}}
}
}

View file

@ -36,7 +36,7 @@ void test() {
// !is_copy_constructible_v<G>,
{
const std::expected<int, NonCopyable> f1(std::unexpect, 0);
f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<int, NonCopyable>::error_or<int>' requested here}}
(void)f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<int, NonCopyable>::error_or<int>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}error_type has to be copy constructible}}
// expected-error-re@*:* {{call to deleted constructor of{{.*}}}}
}
@ -45,7 +45,7 @@ void test() {
// !is_convertible_v<U, T>
{
const std::expected<int, NotConvertibleFromInt> f1(std::unexpect, NotConvertibleFromInt{});
f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<int, NotConvertibleFromInt>::error_or<int>' requested here}}
(void)f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<int, NotConvertibleFromInt>::error_or<int>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}argument has to be convertible to error_type}}
// expected-error-re@*:* {{no viable conversion from returned value of type{{.*}}}}
@ -55,7 +55,7 @@ void test() {
// !is_move_constructible_v<T>,
{
std::expected<int, NonMovable> f1(std::unexpect, 0);
std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<int, NonMovable>::error_or<int>' requested here}}
(void)std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<int, NonMovable>::error_or<int>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}error_type has to be move constructible}}
// expected-error-re@*:* {{call to deleted constructor of{{.*}}}}
}
@ -64,7 +64,7 @@ void test() {
// !is_convertible_v<U, T>
{
std::expected<int, NotConvertibleFromInt> f1(std::unexpect, NotConvertibleFromInt{});
std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<int, NotConvertibleFromInt>::error_or<int>' requested here}}
(void)std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<int, NotConvertibleFromInt>::error_or<int>' requested here}}
//expected-error-re@*:* {{static assertion failed {{.*}}argument has to be convertible to error_type}}
// expected-error-re@*:* {{no viable conversion from returned value of type{{.*}}}}
}

View file

@ -51,7 +51,7 @@ void test() {
// G is not a specialization of std::expected
{
std::expected<int, int> f1(std::unexpected<int>(1));
f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &)>' requested here}}
(void)f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -61,7 +61,7 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
std::expected<int, int> f1(std::unexpected<int>(1));
f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &)>' requested here}}
(void)f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must have the same value_type as this expected}}
}
}
@ -71,7 +71,7 @@ void test() {
// G is not a specialization of std::expected
{
const std::expected<int, int> f1(std::unexpected<int>(1));
f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &)>' requested here}}
(void)f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -81,7 +81,7 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
const std::expected<int, int> f1(std::unexpected<int>(1));
f1.or_else(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &)>' requested here}}
(void)f1.or_else(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must have the same value_type as this expected}}
}
}
@ -91,7 +91,7 @@ void test() {
// G is not a specialization of std::expected
{
std::expected<int, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &&)>' requested here}}
(void)std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -101,7 +101,7 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
std::expected<int, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &&)>' requested here}}
(void)std::move(f1).or_else(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must have the same value_type as this expected}}
}
}
@ -111,7 +111,7 @@ void test() {
// G is not a specialization of std::expected
{
const std::expected<int, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &&)>' requested here}}
(void)std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<int (&)(const int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -121,7 +121,7 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
const std::expected<int, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &&)>' requested here}}
(void)std::move(f1).or_else(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<int, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must have the same value_type as this expected}}
}
}

View file

@ -45,11 +45,11 @@ void test() {
// Test & overload
{
std::expected<int, int> e;
e.transform_error(return_unexpected<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)e.transform_error(return_unexpected<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{static assertion failed {{.*}}[expected.object.general] A program that instantiates the definition of template expected<T, E> for {{.*}} is ill-formed.}}
// expected-error-re@*:* {{union member {{.*}} has reference type {{.*}}}}
e.transform_error(return_no_object<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)e.transform_error(return_no_object<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
// expected-error-re@*:* {{static assertion failed {{.*}}[expected.object.general] A program that instantiates the definition of template expected<T, E> for {{.*}} is ill-formed.}}
}
@ -57,27 +57,27 @@ void test() {
// Test const& overload
{
const std::expected<int, int> e;
e.transform_error(return_unexpected<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)e.transform_error(return_unexpected<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
e.transform_error(return_no_object<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)e.transform_error(return_no_object<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
}
// Test && overload
{
std::expected<int, int> e;
std::move(e).transform_error(return_unexpected<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)std::move(e).transform_error(return_unexpected<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
std::move(e).transform_error(return_no_object<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)std::move(e).transform_error(return_no_object<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
}
// Test const&& overload
{
const std::expected<int, int> e;
std::move(e).transform_error(return_unexpected<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)std::move(e).transform_error(return_unexpected<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
std::move(e).transform_error(return_no_object<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)std::move(e).transform_error(return_no_object<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
}
}

View file

@ -36,7 +36,8 @@ void test() {
// !is_copy_constructible_v<T>,
{
const std::expected<NonCopyable, int> f1{5};
f1.value_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<NonCopyable, int>::value_or<int>' requested here}}
// expected-note@+1 {{in instantiation of function template specialization 'std::expected<NonCopyable, int>::value_or<int>' requested here}}
(void)f1.value_or(5);
// expected-error-re@*:* {{static assertion failed {{.*}}value_type has to be copy constructible}}
}
@ -44,7 +45,8 @@ void test() {
// !is_convertible_v<U, T>
{
const std::expected<NotConvertibleFromInt, int> f1{std::in_place};
f1.value_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<NotConvertibleFromInt, int>::value_or<int>' requested here}}
// expected-note@+1 {{in instantiation of function template specialization 'std::expected<NotConvertibleFromInt, int>::value_or<int>' requested here}}
(void)f1.value_or(5);
//expected-error-re@*:* {{static assertion failed {{.*}}argument has to be convertible to value_type}}
}
@ -52,7 +54,8 @@ void test() {
// !is_move_constructible_v<T>,
{
std::expected<NonMovable, int> f1{5};
std::move(f1).value_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<NonMovable, int>::value_or<int>' requested here}}
// expected-note@+1 {{in instantiation of function template specialization 'std::expected<NonMovable, int>::value_or<int>' requested here}}
(void)std::move(f1).value_or(5);
//expected-error-re@*:* {{static assertion failed {{.*}}value_type has to be move constructible}}
}
@ -60,7 +63,8 @@ void test() {
// !is_convertible_v<U, T>
{
std::expected<NotConvertibleFromInt, int> f1{std::in_place};
std::move(f1).value_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<NotConvertibleFromInt, int>::value_or<int>' requested here}}
// expected-note@+1 {{in instantiation of function template specialization 'std::expected<NotConvertibleFromInt, int>::value_or<int>' requested here}}
(void)std::move(f1).value_or(5);
//expected-error-re@*:* {{static assertion failed {{.*}}argument has to be convertible to value_type}}
}
}

View file

@ -51,7 +51,7 @@ void test() {
// U is not a specialization of std::expected
{
std::expected<void, int> f1;
f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<int (&)()>' requested here}}
(void)f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<int (&)()>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f() must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -61,7 +61,7 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
std::expected<void, int> f1;
f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<std::expected<int, NotSameAsInt> (&)()>' requested here}}
(void)f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<std::expected<int, NotSameAsInt> (&)()>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f() must have the same error_type as this expected}}
}
}
@ -71,7 +71,7 @@ void test() {
// U is not a specialization of std::expected
{
const std::expected<void, int> f1;
f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<int (&)()>' requested here}}
(void)f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<int (&)()>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f() must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -81,7 +81,7 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
const std::expected<void, int> f1;
f1.and_then(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<std::expected<int, NotSameAsInt> (&)()>' requested here}}
(void)f1.and_then(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<std::expected<int, NotSameAsInt> (&)()>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f() must have the same error_type as this expected}}
}
}
@ -91,7 +91,7 @@ void test() {
// U is not a specialization of std::expected
{
std::expected<void, int> f1;
std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<int (&)()>' requested here}}
(void)std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<int (&)()>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f() must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -101,7 +101,7 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
std::expected<void, int> f1;
std::move(f1).and_then(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<std::expected<int, NotSameAsInt> (&)()>' requested here}}
(void)std::move(f1).and_then(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<std::expected<int, NotSameAsInt> (&)()>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f() must have the same error_type as this expected}}
}
}
@ -111,7 +111,7 @@ void test() {
// U is not a specialization of std::expected
{
const std::expected<void, int> f1;
std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<int (&)()>' requested here}}
(void)std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<int (&)()>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f() must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
@ -121,7 +121,7 @@ void test() {
// !std::is_same_v<U:error_type, E>
{
const std::expected<void, int> f1;
std::move(f1).and_then(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<std::expected<int, NotSameAsInt> (&)()>' requested here}}
(void)std::move(f1).and_then(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::and_then<std::expected<int, NotSameAsInt> (&)()>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f() must have the same error_type as this expected}}
}
}

View file

@ -36,7 +36,7 @@ void test() {
// !is_copy_constructible_v<G>,
{
const std::expected<void, NonCopyable> f1(std::unexpect, 0);
f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NonCopyable>::error_or<int>' requested here}}
(void)f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NonCopyable>::error_or<int>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}error_type has to be copy constructible}}
// expected-error-re@*:* {{call to deleted constructor of{{.*}}}}
}
@ -45,7 +45,7 @@ void test() {
// !is_convertible_v<U, T>
{
const std::expected<void, NotConvertibleFromInt> f1(std::unexpect, NotConvertibleFromInt{});
f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NotConvertibleFromInt>::error_or<int>' requested here}}
(void)f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NotConvertibleFromInt>::error_or<int>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}argument has to be convertible to error_type}}
// expected-error-re@*:* {{no viable conversion from returned value of type{{.*}}}}
}
@ -54,7 +54,7 @@ void test() {
// !is_move_constructible_v<T>,
{
std::expected<void, NonMovable> f1(std::unexpect, 0);
std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NonMovable>::error_or<int>' requested here}}
(void)std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NonMovable>::error_or<int>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}error_type has to be move constructible}}
// expected-error-re@*:* {{call to deleted constructor of{{.*}}}}
}
@ -63,7 +63,7 @@ void test() {
// !is_convertible_v<U, T>
{
std::expected<void, NotConvertibleFromInt> f1(std::unexpect, NotConvertibleFromInt{});
std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NotConvertibleFromInt>::error_or<int>' requested here}}
(void)std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected<void, NotConvertibleFromInt>::error_or<int>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}argument has to be convertible to error_type}}
// expected-error-re@*:* {{no viable conversion from returned value of type{{.*}}}}
}

View file

@ -51,7 +51,7 @@ void test() {
// G is not a specialization of std::expected
{
std::expected<void, int> f1(std::unexpected<int>(1));
f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<int (&)(int &)>' requested here}}
(void)f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<int (&)(int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
}
@ -59,7 +59,7 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
std::expected<void, int> f1(std::unexpected<int>(1));
f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &)>' requested here}}
(void)f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must have the same value_type as this expected}}
}
}
@ -69,7 +69,7 @@ void test() {
// G is not a specialization of std::expected
{
const std::expected<void, int> f1(std::unexpected<int>(1));
f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<int (&)(const int &)>' requested here}}
(void)f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<int (&)(const int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
}
@ -77,7 +77,7 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
const std::expected<void, int> f1(std::unexpected<int>(1));
f1.or_else(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &)>' requested here}}
(void)f1.or_else(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(error()) must have the same value_type as this expected}}
}
}
@ -87,7 +87,7 @@ void test() {
// G is not a specialization of std::expected
{
std::expected<void, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<int (&)(int &&)>' requested here}}
(void)std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<int (&)(int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
}
@ -95,7 +95,7 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
std::expected<void, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &&)>' requested here}}
(void)std::move(f1).or_else(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<std::expected<NotSameAsInt, int> (&)(int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must have the same value_type as this expected}}
}
}
@ -105,7 +105,7 @@ void test() {
// G is not a specialization of std::expected
{
const std::expected<void, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<int (&)(const int &&)>' requested here}}
(void)std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<int (&)(const int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must be a specialization of std::expected}}
// expected-error-re@*:* {{{{.*}}cannot be used prior to '::' because it has no members}}
}
@ -113,7 +113,7 @@ void test() {
// !std::is_same_v<G:value_type, T>
{
const std::expected<void, int> f1(std::unexpected<int>(1));
std::move(f1).or_else(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &&)>' requested here}}
(void)std::move(f1).or_else(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected<void, int>::or_else<std::expected<NotSameAsInt, int> (&)(const int &&)>' requested here}}
// expected-error-re@*:* {{static assertion failed {{.*}}The result of f(std::move(error())) must have the same value_type as this expected}}
}
}

View file

@ -45,12 +45,12 @@ void test() {
// Test & overload
{
std::expected<void, int> e;
e.transform_error(return_unexpected<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)e.transform_error(return_unexpected<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
// expected-error-re@*:* {{static assertion failed {{.*}}A program that instantiates expected<T, E> with a E that is not a valid argument for unexpected<E> is ill-formed}}
// expected-error-re@*:* {{union member {{.*}} has reference type {{.*}}}}
e.transform_error(return_no_object<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)e.transform_error(return_no_object<int&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
// expected-error-re@*:* {{static assertion failed {{.*}}A program that instantiates expected<T, E> with a E that is not a valid argument for unexpected<E> is ill-formed}}
}
@ -58,24 +58,24 @@ void test() {
// Test const& overload
{
const std::expected<void, int> e;
e.transform_error(return_unexpected<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)e.transform_error(return_unexpected<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
e.transform_error(return_no_object<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)e.transform_error(return_no_object<const int &>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
// expected-error-re@*:* {{no matching constructor for initialization of{{.*}}}}
}
// Test && overload
{
std::expected<void, int> e;
std::move(e).transform_error(return_unexpected<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
std::move(e).transform_error(return_no_object<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)std::move(e).transform_error(return_unexpected<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)std::move(e).transform_error(return_no_object<int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
}
// Test const&& overload
{
const std::expected<void, int> e;
std::move(e).transform_error(return_unexpected<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
std::move(e).transform_error(return_no_object<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)std::move(e).transform_error(return_unexpected<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
(void)std::move(e).transform_error(return_no_object<const int&&>); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}}
}
}
// clang-format on

View file

@ -30,11 +30,12 @@ void test() {
// MoveOnly type as error_type
std::expected<void, MoveOnly> e(std::unexpect, 5);
e.value(); // expected-note {{in instantiation of member function 'std::expected<void, MoveOnly>::value' requested here}}
// expected-note@+1 {{in instantiation of member function 'std::expected<void, MoveOnly>::value' requested here}}
(void)e.value();
// expected-error@*:* {{static assertion failed due to requirement 'is_copy_constructible_v<MoveOnly>'}}
// expected-error@*:* {{call to deleted constructor of 'MoveOnly'}}
std::move(e)
(void)std::move(e)
.value(); // expected-note {{in instantiation of member function 'std::expected<void, MoveOnly>::value' requested here}}
// expected-error@*:* {{static assertion failed due to requirement 'is_copy_constructible_v<MoveOnly>'}}
@ -42,9 +43,9 @@ void test() {
std::expected<void, CopyOnly> e2(std::unexpect);
// expected-error@*:* {{call to deleted constructor of 'CopyOnly'}}
e2.value();
(void)e2.value();
std::move(e2)
(void)std::move(e2)
.value(); // expected-note {{in instantiation of member function 'std::expected<void, CopyOnly>::value' requested here}}
// expected-error@*:* {{static assertion failed due to requirement 'is_move_constructible_v<CopyOnly>'}}
// expected-error@*:* {{call to deleted constructor of 'CopyOnly'}}

View file

@ -0,0 +1,175 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// <expected>
// Check that functions are marked [[nodiscard]]
#include <expected>
#include <utility>
void test() {
// [expected.bad.void]
class VoidBadExpectedAccess : public std::bad_expected_access<void> {};
VoidBadExpectedAccess voidEx;
const VoidBadExpectedAccess cVoidEx{};
voidEx.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
cVoidEx.what(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// [expected.bad]
std::bad_expected_access<char> ex{'z'};
const std::bad_expected_access<char> cEx{'z'};
ex.error(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
cEx.error(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(ex).error(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cEx).error(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// [expected.expected]
std::expected<int, int> exp;
const std::expected<int, int> cExp{};
*cExp; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
*exp; // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
*std::move(cExp); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
*std::move(exp); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
exp.has_value(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
cExp.value(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
exp.value(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cExp).value(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(exp).value(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
cExp.error(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
exp.error(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cExp).error(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(exp).error(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cExp.value_or(94);
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(exp).value_or(94);
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cExp.error_or(82);
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(exp).error_or(82);
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
exp.and_then([](int&) { return std::expected<int, int>{94}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cExp.and_then([](const int&) { return std::expected<int, int>{94}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(exp).and_then([](int&&) { return std::expected<int, int>{94}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cExp).and_then([](const int&&) { return std::expected<int, int>{94}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
exp.or_else([](int&) { return std::expected<int, int>{82}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cExp.or_else([](const int&) { return std::expected<int, int>{82}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(exp).or_else([](int&&) { return std::expected<int, int>{82}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cExp).or_else([](const int&&) { return std::expected<int, int>{82}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
exp.transform([](int) { return 94; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cExp.transform([](const int) { return 94; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(exp).transform([](int&&) { return 94; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cExp).transform([](const int&&) { return 94; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
exp.transform_error([](int) { return 82; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cExp.transform_error([](const int) { return 82; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(exp).transform_error([](int&&) { return 82; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cExp).transform_error([](const int&&) { return 82; });
// [expected.void]
std::expected<void, int> vExp;
const std::expected<void, int> cVExp{};
vExp.has_value(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cVExp.error();
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
vExp.error();
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cVExp).error();
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(vExp).error();
vExp.error_or(94); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
cVExp.error_or(94); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
vExp.and_then([]() -> std::expected<int, int> { return 82; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cVExp.and_then([]() -> std::expected<int, int> { return 82; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(vExp).and_then([]() -> std::expected<int, int> { return 82; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cVExp).and_then([]() -> std::expected<int, int> { return 82; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
vExp.or_else([](auto) -> std::expected<void, long> { return {}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cVExp.or_else([](auto) -> std::expected<void, long> { return {}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(vExp).or_else([](auto) -> std::expected<void, long> { return {}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cVExp).or_else([](auto) -> std::expected<void, long> { return {}; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
vExp.transform([]() -> int { return 94; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cVExp.transform([]() -> int { return 94; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(vExp).transform([]() -> int { return 94; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cVExp).transform([]() -> int { return 94; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
vExp.transform_error([](auto) -> int { return 82; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cVExp.transform_error([](auto) -> int { return 82; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(vExp).transform_error([](auto) -> int { return 82; });
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cVExp).transform_error([](auto) -> int { return 82; });
// [expected.unexpected]
std::unexpected<char> unex('z');
const std::unexpected<char> cUnex('z');
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
unex.error();
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
cUnex.error();
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(unex).error();
// expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(cUnex).error();
}