[libcxx-commits] [libcxx] [libc++] Implement LWG4406: value_or return statement is inconsistent with Mandates (PR #189568)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Apr 9 12:06:07 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions ,cpp,h -- libcxx/test/libcxx/utilities/optional/optional.object/optional.object.observe/value_or.mandates.verify.cpp libcxx/include/__expected/expected.h libcxx/include/optional libcxx/test/libcxx/utilities/expected/expected.expected/value_or.mandates.verify.cpp libcxx/test/std/utilities/expected/expected.expected/observers/value_or.pass.cpp libcxx/test/std/utilities/optional/optional.object/optional.object.observe/value_or.pass.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libcxx/include/__expected/expected.h b/libcxx/include/__expected/expected.h
index e234dbe58..26cb5bbaf 100644
--- a/libcxx/include/__expected/expected.h
+++ b/libcxx/include/__expected/expected.h
@@ -890,18 +890,18 @@ public:
using _Ret = remove_cv_t<_Tp>;
static_assert(is_convertible_v<const _Tp&, _Ret>,
"expected::value_or: const T& must be implicitly convertible to remove_cv_t<T>");
- static_assert(is_convertible_v<_Up, _Ret>,
- "expected::value_or: U must be implicitly convertible to remove_cv_t<T>");
+ static_assert(
+ is_convertible_v<_Up, _Ret>, "expected::value_or: U must be implicitly convertible to remove_cv_t<T>");
return this->__has_val() ? this->__val() : std::forward<_Up>(__v);
}
template <class _Up = remove_cv_t<_Tp>>
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr remove_cv_t<_Tp> value_or(_Up&& __v) && {
using _Ret = remove_cv_t<_Tp>;
- static_assert(is_convertible_v<_Tp, _Ret>,
- "expected::value_or: T must be implicitly convertible to remove_cv_t<T>");
- static_assert(is_convertible_v<_Up, _Ret>,
- "expected::value_or: U must be implicitly convertible to remove_cv_t<T>");
+ static_assert(
+ is_convertible_v<_Tp, _Ret>, "expected::value_or: T must be implicitly convertible to remove_cv_t<T>");
+ static_assert(
+ is_convertible_v<_Up, _Ret>, "expected::value_or: U must be implicitly convertible to remove_cv_t<T>");
return this->__has_val() ? std::move(this->__val()) : std::forward<_Up>(__v);
}
diff --git a/libcxx/include/optional b/libcxx/include/optional
index ccaec5dc1..f5e610efd 100644
--- a/libcxx/include/optional
+++ b/libcxx/include/optional
@@ -1185,8 +1185,8 @@ public:
using _Ret = remove_cv_t<_Tp>;
static_assert(is_convertible_v<const _Tp&, _Ret>,
"optional<T>::value_or: const T& must be implicitly convertible to remove_cv_t<T>");
- static_assert(is_convertible_v<_Up, _Ret>,
- "optional<T>::value_or: U must be implicitly convertible to remove_cv_t<T>");
+ static_assert(
+ is_convertible_v<_Up, _Ret>, "optional<T>::value_or: U must be implicitly convertible to remove_cv_t<T>");
return this->has_value() ? this->__get() : std::forward<_Up>(__v);
}
@@ -1196,10 +1196,10 @@ public:
# endif
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr remove_cv_t<_Tp> value_or(_Up&& __v) && {
using _Ret = remove_cv_t<_Tp>;
- static_assert(is_convertible_v<_Tp, _Ret>,
- "optional<T>::value_or: T must be implicitly convertible to remove_cv_t<T>");
- static_assert(is_convertible_v<_Up, _Ret>,
- "optional<T>::value_or: U must be implicitly convertible to remove_cv_t<T>");
+ static_assert(
+ is_convertible_v<_Tp, _Ret>, "optional<T>::value_or: T must be implicitly convertible to remove_cv_t<T>");
+ static_assert(
+ is_convertible_v<_Up, _Ret>, "optional<T>::value_or: U must be implicitly convertible to remove_cv_t<T>");
return this->has_value() ? std::move(this->__get()) : std::forward<_Up>(__v);
}
@@ -1356,10 +1356,10 @@ public:
!is_array_v<__libcpp_remove_reference_t<_Tp>>)
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decay_t<_Tp> value_or(_Up&& __v) const {
using _Ret = remove_cvref_t<_Tp>;
- static_assert(is_convertible_v<_Tp&, _Ret>,
- "optional<T&>::value_or: T& must be implicitly convertible to remove_cv_t<T>");
- static_assert(is_convertible_v<_Up, _Ret>,
- "optional<T&>::value_or: U must be implicitly convertible to remove_cv_t<T>");
+ static_assert(
+ is_convertible_v<_Tp&, _Ret>, "optional<T&>::value_or: T& must be implicitly convertible to remove_cv_t<T>");
+ static_assert(
+ is_convertible_v<_Up, _Ret>, "optional<T&>::value_or: U must be implicitly convertible to remove_cv_t<T>");
return this->has_value() ? this->__get() : std::forward<_Up>(__v);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/189568
More information about the libcxx-commits
mailing list