diff --git a/libcxx/include/__expected/bad_expected_access.h b/libcxx/include/__expected/bad_expected_access.h index 1b734389e8311..b1958101d5178 100644 --- a/libcxx/include/__expected/bad_expected_access.h +++ b/libcxx/include/__expected/bad_expected_access.h @@ -43,9 +43,11 @@ class _LIBCPP_EXPORTED_FROM_ABI bad_expected_access : public exception { 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 { 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_; diff --git a/libcxx/include/__expected/expected.h b/libcxx/include/__expected/expected.h index be37e8ab66ac4..b6a9211ae3cdc 100644 --- a/libcxx/include/__expected/expected.h +++ b/libcxx/include/__expected/expected.h @@ -798,25 +798,25 @@ class expected : private __expected_base<_Tp, _Err> { 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 @@ class expected : private __expected_base<_Tp, _Err> { _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 @@ class expected : private __expected_base<_Tp, _Err> { 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 @@ class expected : private __expected_base<_Tp, _Err> { 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 @@ class expected : private __expected_base<_Tp, _Err> { 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 @@ class expected : private __expected_base<_Tp, _Err> { 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 > - _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 > - _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 - _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 @@ class expected : private __expected_base<_Tp, _Err> { } template - _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 @@ class expected : private __expected_base<_Tp, _Err> { // [expected.void.monadic], monadic template 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>; static_assert(__is_std_expected<_Up>::value, "The result of f(value()) must be a specialization of std::expected"); static_assert(is_same_v, @@ -932,7 +932,7 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; static_assert(__is_std_expected<_Up>::value, "The result of f(value()) must be a specialization of std::expected"); static_assert(is_same_v, @@ -945,7 +945,7 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; 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 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; 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 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; static_assert(__is_std_expected<_Gp>::value, "The result of f(error()) must be a specialization of std::expected"); static_assert(is_same_v, @@ -986,7 +986,7 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; static_assert(__is_std_expected<_Gp>::value, "The result of f(error()) must be a specialization of std::expected"); static_assert(is_same_v, @@ -999,7 +999,7 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; 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 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; 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 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; if (!has_value()) { return expected<_Up, _Err>(unexpect, error()); @@ -1043,7 +1043,7 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; if (!has_value()) { return expected<_Up, _Err>(unexpect, error()); @@ -1059,7 +1059,7 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; if (!has_value()) { return expected<_Up, _Err>(unexpect, std::move(error())); @@ -1075,7 +1075,7 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; if (!has_value()) { return expected<_Up, _Err>(unexpect, std::move(error())); @@ -1091,7 +1091,7 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; static_assert(__valid_std_unexpected<_Gp>::value, "The result of f(error()) must be a valid template argument for unexpected"); @@ -1103,7 +1103,7 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; static_assert(__valid_std_unexpected<_Gp>::value, "The result of f(error()) must be a valid template argument for unexpected"); @@ -1115,7 +1115,7 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; 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 @@ class expected : private __expected_base<_Tp, _Err> { template 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>; static_assert(__valid_std_unexpected<_Gp>::value, "The result of f(std::move(error())) must be a valid template argument for unexpected"); @@ -1145,8 +1145,8 @@ class expected : private __expected_base<_Tp, _Err> { requires(!is_void_v<_T2>) # if _LIBCPP_STD_VER >= 26 && requires { - { *__x == *__y } -> __core_convertible_to; - { __x.error() == __y.error() } -> __core_convertible_to; + { *__x == *__y }->__core_convertible_to; + { __x.error() == __y.error() }->__core_convertible_to; } # endif { @@ -1165,7 +1165,7 @@ class expected : private __expected_base<_Tp, _Err> { _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const _T2& __v) # if _LIBCPP_STD_VER >= 26 requires(!__is_std_expected<_T2>::value) && requires { - { *__x == __v } -> __core_convertible_to; + { *__x == __v }->__core_convertible_to; } # endif { @@ -1176,7 +1176,7 @@ class expected : private __expected_base<_Tp, _Err> { _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const unexpected<_E2>& __e) # if _LIBCPP_STD_VER >= 26 requires requires { - { __x.error() == __e.error() } -> __core_convertible_to; + { __x.error() == __e.error() }->__core_convertible_to; } # endif { @@ -1595,7 +1595,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { // [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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { } } - _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 - _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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { } template - _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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { // [expected.void.monadic], monadic template 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>; static_assert(__is_std_expected<_Up>::value, "The result of f() must be a specialization of std::expected"); static_assert( @@ -1676,7 +1676,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { template 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>; static_assert(__is_std_expected<_Up>::value, "The result of f() must be a specialization of std::expected"); static_assert( @@ -1689,7 +1689,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { template 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>; static_assert(__is_std_expected<_Up>::value, "The result of f() must be a specialization of std::expected"); static_assert( @@ -1702,7 +1702,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { template 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>; static_assert(__is_std_expected<_Up>::value, "The result of f() must be a specialization of std::expected"); static_assert( @@ -1714,7 +1714,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { } template - _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>; static_assert(__is_std_expected<_Gp>::value, "The result of f(error()) must be a specialization of std::expected"); static_assert(is_same_v, @@ -1726,7 +1726,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { } template - _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>; static_assert(__is_std_expected<_Gp>::value, "The result of f(error()) must be a specialization of std::expected"); static_assert(is_same_v, @@ -1738,7 +1738,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { } template - _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>; 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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { } template - _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>; 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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { template 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>; if (!has_value()) { return expected<_Up, _Err>(unexpect, error()); @@ -1780,7 +1780,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { template 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>; if (!has_value()) { return expected<_Up, _Err>(unexpect, error()); @@ -1795,7 +1795,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { template 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>; if (!has_value()) { return expected<_Up, _Err>(unexpect, std::move(error())); @@ -1810,7 +1810,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { template 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>; if (!has_value()) { return expected<_Up, _Err>(unexpect, std::move(error())); @@ -1824,7 +1824,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { } template - _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>; static_assert(__valid_std_unexpected<_Gp>::value, "The result of f(error()) must be a valid template argument for unexpected"); @@ -1835,7 +1835,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { } template - _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>; static_assert(__valid_std_unexpected<_Gp>::value, "The result of f(error()) must be a valid template argument for unexpected"); @@ -1846,7 +1846,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { } template - _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>; 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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { } template - _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>; static_assert(__valid_std_unexpected<_Gp>::value, "The result of f(std::move(error())) must be a valid template argument for unexpected"); @@ -1875,7 +1875,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y) # if _LIBCPP_STD_VER >= 26 requires requires { - { __x.error() == __y.error() } -> __core_convertible_to; + { __x.error() == __y.error() }->__core_convertible_to; } # endif { @@ -1890,7 +1890,7 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> { _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const unexpected<_E2>& __y) # if _LIBCPP_STD_VER >= 26 requires requires { - { __x.error() == __y.error() } -> __core_convertible_to; + { __x.error() == __y.error() }->__core_convertible_to; } # endif { diff --git a/libcxx/include/__expected/unexpected.h b/libcxx/include/__expected/unexpected.h index 6904889b8c6b1..fc4f52ce14adc 100644 --- a/libcxx/include/__expected/unexpected.h +++ b/libcxx/include/__expected/unexpected.h @@ -89,10 +89,10 @@ class unexpected { _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 to be true"); diff --git a/libcxx/test/libcxx/utilities/expected/expected.expected/and_then.mandates.verify.cpp b/libcxx/test/libcxx/utilities/expected/expected.expected/and_then.mandates.verify.cpp index fbd2317ebeee2..bee905faecf72 100644 --- a/libcxx/test/libcxx/utilities/expected/expected.expected/and_then.mandates.verify.cpp +++ b/libcxx/test/libcxx/utilities/expected/expected.expected/and_then.mandates.verify.cpp @@ -51,7 +51,7 @@ void test() { // U is not a specialization of std::expected { std::expected f1(1); - f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' requested here}} + (void)f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' 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 { std::expected f1(1); - f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::and_then (&)(int &)>' requested here}} + (void)f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::and_then (&)(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 f1(1); - f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' requested here}} + (void)f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' 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 { const std::expected f1(1); - f1.and_then(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::and_then (&)(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::and_then (&)(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 f1(1); - std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' requested here}} + (void)std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' 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 { std::expected f1(1); - std::move(f1).and_then(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::and_then (&)(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::and_then (&)(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 f1(1); - std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' requested here}} + (void)std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' 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 { const std::expected f1(1); - std::move(f1).and_then(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::and_then (&)(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::and_then (&)(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}} } } diff --git a/libcxx/test/libcxx/utilities/expected/expected.expected/error_or.mandates.verify.cpp b/libcxx/test/libcxx/utilities/expected/expected.expected/error_or.mandates.verify.cpp index d833f72f1c54f..34b257fc0e688 100644 --- a/libcxx/test/libcxx/utilities/expected/expected.expected/error_or.mandates.verify.cpp +++ b/libcxx/test/libcxx/utilities/expected/expected.expected/error_or.mandates.verify.cpp @@ -36,7 +36,7 @@ void test() { // !is_copy_constructible_v, { const std::expected f1(std::unexpect, 0); - f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' requested here}} + (void)f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' 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 { const std::expected f1(std::unexpect, NotConvertibleFromInt{}); - f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' requested here}} + (void)f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' 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, { std::expected f1(std::unexpect, 0); - std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' requested here}} + (void)std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' 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 { std::expected f1(std::unexpect, NotConvertibleFromInt{}); - std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' requested here}} + (void)std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' 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{{.*}}}} } diff --git a/libcxx/test/libcxx/utilities/expected/expected.expected/or_else.mandates.verify.cpp b/libcxx/test/libcxx/utilities/expected/expected.expected/or_else.mandates.verify.cpp index 553ac4c6033a5..05992a81bcddb 100644 --- a/libcxx/test/libcxx/utilities/expected/expected.expected/or_else.mandates.verify.cpp +++ b/libcxx/test/libcxx/utilities/expected/expected.expected/or_else.mandates.verify.cpp @@ -51,7 +51,7 @@ void test() { // G is not a specialization of std::expected { std::expected f1(std::unexpected(1)); - f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' requested here}} + (void)f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' 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 { std::expected f1(std::unexpected(1)); - f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::or_else (&)(int &)>' requested here}} + (void)f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::or_else (&)(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 f1(std::unexpected(1)); - f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' requested here}} + (void)f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' 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 { const std::expected f1(std::unexpected(1)); - f1.or_else(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::or_else (&)(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::or_else (&)(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 f1(std::unexpected(1)); - std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' requested here}} + (void)std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' 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 { std::expected f1(std::unexpected(1)); - std::move(f1).or_else(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::or_else (&)(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::or_else (&)(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 f1(std::unexpected(1)); - std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' requested here}} + (void)std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' 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 { const std::expected f1(std::unexpected(1)); - std::move(f1).or_else(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::or_else (&)(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::or_else (&)(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}} } } diff --git a/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp b/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp index 3e9bdd98cd394..8a4ec7aeb24be 100644 --- a/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp +++ b/libcxx/test/libcxx/utilities/expected/expected.expected/transform_error.mandates.verify.cpp @@ -45,11 +45,11 @@ void test() { // Test & overload { std::expected e; - e.transform_error(return_unexpected); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}} + (void)e.transform_error(return_unexpected); // 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 for {{.*}} is ill-formed.}} // expected-error-re@*:* {{union member {{.*}} has reference type {{.*}}}} - e.transform_error(return_no_object); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}} + (void)e.transform_error(return_no_object); // 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 for {{.*}} is ill-formed.}} } @@ -57,27 +57,27 @@ void test() { // Test const& overload { const std::expected e; - e.transform_error(return_unexpected); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}} + (void)e.transform_error(return_unexpected); // 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); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}} + (void)e.transform_error(return_no_object); // 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 e; - std::move(e).transform_error(return_unexpected); // 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); // 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); // 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); // 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 e; - std::move(e).transform_error(return_unexpected); // 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); // 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); // 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); // 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{{.*}}}} } } diff --git a/libcxx/test/libcxx/utilities/expected/expected.expected/value_or.mandates.verify.cpp b/libcxx/test/libcxx/utilities/expected/expected.expected/value_or.mandates.verify.cpp index 5d26f36f35d38..75c541c194b59 100644 --- a/libcxx/test/libcxx/utilities/expected/expected.expected/value_or.mandates.verify.cpp +++ b/libcxx/test/libcxx/utilities/expected/expected.expected/value_or.mandates.verify.cpp @@ -36,7 +36,8 @@ void test() { // !is_copy_constructible_v, { const std::expected f1{5}; - f1.value_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::value_or' requested here}} + // expected-note@+1 {{in instantiation of function template specialization 'std::expected::value_or' 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 { const std::expected f1{std::in_place}; - f1.value_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::value_or' requested here}} + // expected-note@+1 {{in instantiation of function template specialization 'std::expected::value_or' 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, { std::expected f1{5}; - std::move(f1).value_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::value_or' requested here}} + // expected-note@+1 {{in instantiation of function template specialization 'std::expected::value_or' 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 { std::expected f1{std::in_place}; - std::move(f1).value_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::value_or' requested here}} + // expected-note@+1 {{in instantiation of function template specialization 'std::expected::value_or' requested here}} + (void)std::move(f1).value_or(5); //expected-error-re@*:* {{static assertion failed {{.*}}argument has to be convertible to value_type}} } } diff --git a/libcxx/test/libcxx/utilities/expected/expected.void/and_then.mandates.verify.cpp b/libcxx/test/libcxx/utilities/expected/expected.void/and_then.mandates.verify.cpp index 1df6cbf543b4f..0d27ddf9884c4 100644 --- a/libcxx/test/libcxx/utilities/expected/expected.void/and_then.mandates.verify.cpp +++ b/libcxx/test/libcxx/utilities/expected/expected.void/and_then.mandates.verify.cpp @@ -51,7 +51,7 @@ void test() { // U is not a specialization of std::expected { std::expected f1; - f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' requested here}} + (void)f1.and_then(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' 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 { std::expected f1; - f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::and_then (&)()>' requested here}} + (void)f1.and_then(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::and_then (&)()>' 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 f1; - f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' requested here}} + (void)f1.and_then(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' 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 { const std::expected f1; - f1.and_then(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::and_then (&)()>' requested here}} + (void)f1.and_then(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::and_then (&)()>' 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 f1; - std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' requested here}} + (void)std::move(f1).and_then(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' 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 { std::expected f1; - std::move(f1).and_then(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::and_then (&)()>' 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::and_then (&)()>' 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 f1; - std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' requested here}} + (void)std::move(f1).and_then(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::and_then' 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 { const std::expected f1; - std::move(f1).and_then(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::and_then (&)()>' 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::and_then (&)()>' requested here}} // expected-error-re@*:* {{static assertion failed {{.*}}The result of f() must have the same error_type as this expected}} } } diff --git a/libcxx/test/libcxx/utilities/expected/expected.void/error_or.mandates.verify.cpp b/libcxx/test/libcxx/utilities/expected/expected.void/error_or.mandates.verify.cpp index 21f93b8285d2e..9259ed5e176d3 100644 --- a/libcxx/test/libcxx/utilities/expected/expected.void/error_or.mandates.verify.cpp +++ b/libcxx/test/libcxx/utilities/expected/expected.void/error_or.mandates.verify.cpp @@ -36,7 +36,7 @@ void test() { // !is_copy_constructible_v, { const std::expected f1(std::unexpect, 0); - f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' requested here}} + (void)f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' 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 { const std::expected f1(std::unexpect, NotConvertibleFromInt{}); - f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' requested here}} + (void)f1.error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' 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, { std::expected f1(std::unexpect, 0); - std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' requested here}} + (void)std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' 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 { std::expected f1(std::unexpect, NotConvertibleFromInt{}); - std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' requested here}} + (void)std::move(f1).error_or(5); // expected-note{{in instantiation of function template specialization 'std::expected::error_or' 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{{.*}}}} } diff --git a/libcxx/test/libcxx/utilities/expected/expected.void/or_else.mandates.verify.cpp b/libcxx/test/libcxx/utilities/expected/expected.void/or_else.mandates.verify.cpp index 3046d09d6af55..7916290f253c3 100644 --- a/libcxx/test/libcxx/utilities/expected/expected.void/or_else.mandates.verify.cpp +++ b/libcxx/test/libcxx/utilities/expected/expected.void/or_else.mandates.verify.cpp @@ -51,7 +51,7 @@ void test() { // G is not a specialization of std::expected { std::expected f1(std::unexpected(1)); - f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' requested here}} + (void)f1.or_else(lval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' 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 { std::expected f1(std::unexpected(1)); - f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::or_else (&)(int &)>' requested here}} + (void)f1.or_else(lval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::or_else (&)(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 f1(std::unexpected(1)); - f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' requested here}} + (void)f1.or_else(clval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' 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 { const std::expected f1(std::unexpected(1)); - f1.or_else(clval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::or_else (&)(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::or_else (&)(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 f1(std::unexpected(1)); - std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' requested here}} + (void)std::move(f1).or_else(rval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' 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 { std::expected f1(std::unexpected(1)); - std::move(f1).or_else(rval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::or_else (&)(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::or_else (&)(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 f1(std::unexpected(1)); - std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' requested here}} + (void)std::move(f1).or_else(crval_return_not_std_expected); // expected-note{{in instantiation of function template specialization 'std::expected::or_else' 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 { const std::expected f1(std::unexpected(1)); - std::move(f1).or_else(crval_error_type_not_same_as_int); // expected-note{{in instantiation of function template specialization 'std::expected::or_else (&)(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::or_else (&)(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}} } } diff --git a/libcxx/test/libcxx/utilities/expected/expected.void/transform_error.mandates.verify.cpp b/libcxx/test/libcxx/utilities/expected/expected.void/transform_error.mandates.verify.cpp index c5acc27af03ea..e45fd645c5a6d 100644 --- a/libcxx/test/libcxx/utilities/expected/expected.void/transform_error.mandates.verify.cpp +++ b/libcxx/test/libcxx/utilities/expected/expected.void/transform_error.mandates.verify.cpp @@ -45,12 +45,12 @@ void test() { // Test & overload { std::expected e; - e.transform_error(return_unexpected); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}} + (void)e.transform_error(return_unexpected); // 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 with a E that is not a valid argument for unexpected is ill-formed}} // expected-error-re@*:* {{union member {{.*}} has reference type {{.*}}}} - e.transform_error(return_no_object); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}} + (void)e.transform_error(return_no_object); // 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 with a E that is not a valid argument for unexpected is ill-formed}} } @@ -58,24 +58,24 @@ void test() { // Test const& overload { const std::expected e; - e.transform_error(return_unexpected); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}} + (void)e.transform_error(return_unexpected); // 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); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}} + (void)e.transform_error(return_no_object); // 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 e; - std::move(e).transform_error(return_unexpected); // 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); // 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); // 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); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}} } // Test const&& overload { const std::expected e; - std::move(e).transform_error(return_unexpected); // 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); // 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); // 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); // expected-error-re@*:* {{static assertion failed {{.*}}The result of {{.*}} must be a valid template argument for unexpected}} } } // clang-format on diff --git a/libcxx/test/libcxx/utilities/expected/expected.void/value.lwg3940.verify.cpp b/libcxx/test/libcxx/utilities/expected/expected.void/value.lwg3940.verify.cpp index 253ef1d5483b8..047ca7c304abe 100644 --- a/libcxx/test/libcxx/utilities/expected/expected.void/value.lwg3940.verify.cpp +++ b/libcxx/test/libcxx/utilities/expected/expected.void/value.lwg3940.verify.cpp @@ -30,11 +30,12 @@ void test() { // MoveOnly type as error_type std::expected e(std::unexpect, 5); - e.value(); // expected-note {{in instantiation of member function 'std::expected::value' requested here}} + // expected-note@+1 {{in instantiation of member function 'std::expected::value' requested here}} + (void)e.value(); // expected-error@*:* {{static assertion failed due to requirement 'is_copy_constructible_v'}} // 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::value' requested here}} // expected-error@*:* {{static assertion failed due to requirement 'is_copy_constructible_v'}} @@ -42,9 +43,9 @@ void test() { std::expected 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::value' requested here}} // expected-error@*:* {{static assertion failed due to requirement 'is_move_constructible_v'}} // expected-error@*:* {{call to deleted constructor of 'CopyOnly'}} diff --git a/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp b/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp new file mode 100644 index 0000000000000..c9af7a91c67f2 --- /dev/null +++ b/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp @@ -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 + +// + +// Check that functions are marked [[nodiscard]] + +#include +#include + +void test() { + // [expected.bad.void] + + class VoidBadExpectedAccess : public std::bad_expected_access {}; + + 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 ex{'z'}; + const std::bad_expected_access 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 exp; + const std::expected 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{94}; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + cExp.and_then([](const int&) { return std::expected{94}; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + std::move(exp).and_then([](int&&) { return std::expected{94}; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + std::move(cExp).and_then([](const int&&) { return std::expected{94}; }); + + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + exp.or_else([](int&) { return std::expected{82}; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + cExp.or_else([](const int&) { return std::expected{82}; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + std::move(exp).or_else([](int&&) { return std::expected{82}; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + std::move(cExp).or_else([](const int&&) { return std::expected{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 vExp; + const std::expected 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 { return 82; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + cVExp.and_then([]() -> std::expected { return 82; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + std::move(vExp).and_then([]() -> std::expected { return 82; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + std::move(cVExp).and_then([]() -> std::expected { return 82; }); + + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + vExp.or_else([](auto) -> std::expected { return {}; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + cVExp.or_else([](auto) -> std::expected { return {}; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + std::move(vExp).or_else([](auto) -> std::expected { return {}; }); + // expected-warning@+1 {{ignoring return value of function declared with 'nodiscard' attribute}} + std::move(cVExp).or_else([](auto) -> std::expected { 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 unex('z'); + const std::unexpected 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(); +}