[libcxx-commits] [libcxx] [libc++][expected] Applied `[[nodiscard]]` (PR #170245)
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Dec 14 01:14:24 PST 2025
https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/170245
>From ef8aa11acd8f6139f4159932a0433e3af2dc07fc Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 2 Dec 2025 07:28:24 +0200
Subject: [PATCH 1/4] [libc++][expected] Applied `[[nodiscard]]`
[[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
---
.../include/__expected/bad_expected_access.h | 14 +-
libcxx/include/__expected/expected.h | 124 +++++------
libcxx/include/__expected/unexpected.h | 8 +-
.../and_then.mandates.verify.cpp | 16 +-
.../error_or.mandates.verify.cpp | 8 +-
.../or_else.mandates.verify.cpp | 16 +-
.../transform_error.mandates.verify.cpp | 16 +-
.../value_or.mandates.verify.cpp | 12 +-
.../and_then.mandates.verify.cpp | 16 +-
.../error_or.mandates.verify.cpp | 8 +-
.../expected.void/or_else.mandates.verify.cpp | 16 +-
.../transform_error.mandates.verify.cpp | 16 +-
.../expected.void/value.lwg3940.verify.cpp | 9 +-
.../utilities/expected/nodiscard.verify.cpp | 203 ++++++++++++++++++
14 files changed, 346 insertions(+), 136 deletions(-)
create mode 100644 libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp
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<void> : 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<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_;
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 <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 @@ class expected : private __expected_base<_Tp, _Err> {
}
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 @@ class expected : private __expected_base<_Tp, _Err> {
// [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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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 @@ class expected : private __expected_base<_Tp, _Err> {
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");
@@ -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<bool>;
- { __x.error() == __y.error() } -> __core_convertible_to<bool>;
+ { *__x == *__y }->__core_convertible_to<bool>;
+ { __x.error() == __y.error() }->__core_convertible_to<bool>;
}
# 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<bool>;
+ { *__x == __v }->__core_convertible_to<bool>;
}
# 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<bool>;
+ { __x.error() == __e.error() }->__core_convertible_to<bool>;
}
# 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 <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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
}
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
// [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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
}
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
}
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
}
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
}
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
}
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
}
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
}
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 @@ class expected<_Tp, _Err> : private __expected_void_base<_Err> {
}
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");
@@ -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<bool>;
+ { __x.error() == __y.error() }->__core_convertible_to<bool>;
}
# 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<bool>;
+ { __x.error() == __y.error() }->__core_convertible_to<bool>;
}
# 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<E> 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<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}}
}
}
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<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{{.*}}}}
}
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<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}}
}
}
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<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{{.*}}}}
}
}
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<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 at +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 at +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 at +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 at +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}}
}
}
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<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}}
}
}
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<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{{.*}}}}
}
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<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}}
}
}
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<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
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<void, MoveOnly> e(std::unexpect, 5);
- e.value(); // expected-note {{in instantiation of member function 'std::expected<void, MoveOnly>::value' requested here}}
+ // expected-note at +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'}}
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..afaeb9f09642f
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp
@@ -0,0 +1,203 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+struct LVal {
+ constexpr std::expected<int, int> operator()(int&) { return 1; }
+ std::expected<int, int> operator()(const int&) = delete;
+ std::expected<int, int> operator()(int&&) = delete;
+ std::expected<int, int> operator()(const int&&) = delete;
+};
+
+struct CLVal {
+ std::expected<int, int> operator()(int&) = delete;
+ constexpr std::expected<int, int> operator()(const int&) { return 1; }
+ std::expected<int, int> operator()(int&&) = delete;
+ std::expected<int, int> operator()(const int&&) = delete;
+};
+
+struct RVal {
+ std::expected<int, int> operator()(int&) = delete;
+ std::expected<int, int> operator()(const int&) = delete;
+ constexpr std::expected<int, int> operator()(int&&) { return 1; }
+ std::expected<int, int> operator()(const int&&) = delete;
+};
+
+struct CRVal {
+ std::expected<int, int> operator()(int&) = delete;
+ std::expected<int, int> operator()(const int&) = delete;
+ std::expected<int, int> operator()(int&&) = delete;
+ constexpr std::expected<int, int> operator()(const int&&) { return 1; }
+};
+
+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 at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cExp.value_or(94);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(exp).value_or(94);
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cExp.error_or(82);
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(exp).error_or(82);
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ exp.and_then(LVal{});
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cExp.and_then(CLVal{});
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(exp).and_then(RVal{});
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(cExp).and_then(CRVal{});
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ exp.or_else(LVal{});
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cExp.or_else(CLVal{});
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(exp).or_else(RVal{});
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(cExp).or_else(CRVal{});
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ exp.transform([](int) { return 94; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cExp.transform([](const int) { return 94; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(exp).transform([](int&&) { return 94; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(cExp).transform([](const int&&) { return 94; });
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ exp.transform_error([](int) { return 82; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cExp.transform_error([](const int) { return 82; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(exp).transform_error([](int&&) { return 82; });
+ // expected-warning at +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 at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cVExp.error();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ vExp.error();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(cVExp).error();
+ // expected-warning at +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 at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ vExp.and_then([]() -> std::expected<int, int> { return 82; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cVExp.and_then([]() -> std::expected<int, int> { return 82; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(vExp).and_then([]() -> std::expected<int, int> { return 82; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(cVExp).and_then([]() -> std::expected<int, int> { return 82; });
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ vExp.or_else([](auto) -> std::expected<void, long> { return {}; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cVExp.or_else([](auto) -> std::expected<void, long> { return {}; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(vExp).or_else([](auto) -> std::expected<void, long> { return {}; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(cVExp).or_else([](auto) -> std::expected<void, long> { return {}; });
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ vExp.transform([]() -> int { return 94; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cVExp.transform([]() -> int { return 94; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(vExp).transform([]() -> int { return 94; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(cVExp).transform([]() -> int { return 94; });
+
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ vExp.transform_error([](auto) -> int { return 82; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cVExp.transform_error([](auto) -> int { return 82; });
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(vExp).transform_error([](auto) -> int { return 82; });
+ // expected-warning at +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 at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ unex.error();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ cUnex.error();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(unex).error();
+ // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+ std::move(cUnex).error();
+}
>From e7357418c6c2d8b359977451386af84eae89762b Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Tue, 2 Dec 2025 11:24:09 +0200
Subject: [PATCH 2/4] Simplified tests
---
.../utilities/expected/nodiscard.verify.cpp | 48 ++++---------------
1 file changed, 10 insertions(+), 38 deletions(-)
diff --git a/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp b/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp
index afaeb9f09642f..c9af7a91c67f2 100644
--- a/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/utilities/expected/nodiscard.verify.cpp
@@ -15,34 +15,6 @@
#include <expected>
#include <utility>
-struct LVal {
- constexpr std::expected<int, int> operator()(int&) { return 1; }
- std::expected<int, int> operator()(const int&) = delete;
- std::expected<int, int> operator()(int&&) = delete;
- std::expected<int, int> operator()(const int&&) = delete;
-};
-
-struct CLVal {
- std::expected<int, int> operator()(int&) = delete;
- constexpr std::expected<int, int> operator()(const int&) { return 1; }
- std::expected<int, int> operator()(int&&) = delete;
- std::expected<int, int> operator()(const int&&) = delete;
-};
-
-struct RVal {
- std::expected<int, int> operator()(int&) = delete;
- std::expected<int, int> operator()(const int&) = delete;
- constexpr std::expected<int, int> operator()(int&&) { return 1; }
- std::expected<int, int> operator()(const int&&) = delete;
-};
-
-struct CRVal {
- std::expected<int, int> operator()(int&) = delete;
- std::expected<int, int> operator()(const int&) = delete;
- std::expected<int, int> operator()(int&&) = delete;
- constexpr std::expected<int, int> operator()(const int&&) { return 1; }
-};
-
void test() {
// [expected.bad.void]
@@ -56,8 +28,8 @@ void test() {
// [expected.bad]
- std::bad_expected_access<char> ex('z');
- const std::bad_expected_access<char> cEx('z');
+ 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}}
@@ -97,22 +69,22 @@ void test() {
std::move(exp).error_or(82);
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- exp.and_then(LVal{});
+ exp.and_then([](int&) { return std::expected<int, int>{94}; });
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- cExp.and_then(CLVal{});
+ cExp.and_then([](const int&) { return std::expected<int, int>{94}; });
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::move(exp).and_then(RVal{});
+ std::move(exp).and_then([](int&&) { return std::expected<int, int>{94}; });
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::move(cExp).and_then(CRVal{});
+ std::move(cExp).and_then([](const int&&) { return std::expected<int, int>{94}; });
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- exp.or_else(LVal{});
+ exp.or_else([](int&) { return std::expected<int, int>{82}; });
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- cExp.or_else(CLVal{});
+ cExp.or_else([](const int&) { return std::expected<int, int>{82}; });
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::move(exp).or_else(RVal{});
+ std::move(exp).or_else([](int&&) { return std::expected<int, int>{82}; });
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
- std::move(cExp).or_else(CRVal{});
+ std::move(cExp).or_else([](const int&&) { return std::expected<int, int>{82}; });
// expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
exp.transform([](int) { return 94; });
>From 60c468a9fb2e8029c5e59f67101aad960e328b04 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Fri, 12 Dec 2025 08:09:41 +0200
Subject: [PATCH 3/4] Adressed review comments
---
libcxx/include/__expected/expected.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libcxx/include/__expected/expected.h b/libcxx/include/__expected/expected.h
index b6a9211ae3cdc..983f203d8ca65 100644
--- a/libcxx/include/__expected/expected.h
+++ b/libcxx/include/__expected/expected.h
@@ -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<bool>;
- { __x.error() == __y.error() }->__core_convertible_to<bool>;
+ { *__x == *__y } -> __core_convertible_to<bool>;
+ { __x.error() == __y.error() } -> __core_convertible_to<bool>;
}
# endif
{
>From 969f5b8180a682df0b27167ffa9c99c0f4464909 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Sun, 14 Dec 2025 11:13:03 +0200
Subject: [PATCH 4/4] Addressed review comments
---
libcxx/include/__expected/expected.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libcxx/include/__expected/expected.h b/libcxx/include/__expected/expected.h
index 983f203d8ca65..24ae33d4e3af8 100644
--- a/libcxx/include/__expected/expected.h
+++ b/libcxx/include/__expected/expected.h
@@ -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<bool>;
+ { *__x == __v } -> __core_convertible_to<bool>;
}
# 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<bool>;
+ { __x.error() == __e.error() } -> __core_convertible_to<bool>;
}
# endif
{
@@ -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<bool>;
+ { __x.error() == __y.error() } -> __core_convertible_to<bool>;
}
# 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<bool>;
+ { __x.error() == __y.error() } -> __core_convertible_to<bool>;
}
# endif
{
More information about the libcxx-commits
mailing list