[libcxx-commits] [libcxx] [libc++] Fix bug where optional<T&> couldn't be constructed from a monadic operation (PR #203462)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jun 11 23:25:55 PDT 2026
================
@@ -776,6 +784,14 @@ template <class _Tp, class _Up, class... _Args>
inline constexpr bool __is_constructible_for_optional_initializer_list_v<_Tp&, _Up, _Args...> = false;
# endif
+# if _LIBCPP_STD_VER >= 26
+template <class _Tp>
+inline constexpr bool __is_valid_optional_type = is_object_v<_Tp> || is_lvalue_reference_v<_Tp>;
+# else
+template <class _Tp>
+inline constexpr bool __is_valid_optional_type = is_object_v<_Tp>;
+# endif
----------------
frederick-vs-ja wrote:
(Sorry for a possibly separated mail. This part isn't quite change-requested.)
Would it be clearer to only guard the portion added in C++26?
```suggestion
template <class _Tp>
inline constexpr bool __is_valid_optional_type =
# if _LIBCPP_STD_VER >= 26
is_lvalue_reference_v<_Tp> ||
# endif
is_object_v<_Tp>;
```
Also, would it be clearer to rename this to `__is_valid_optional_contained_type`?
https://github.com/llvm/llvm-project/pull/203462
More information about the libcxx-commits
mailing list