[libcxx-commits] [libcxx] [libc++] Cooperation between `std::optional` and other standard types (PR #93672)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Mon Apr 7 00:13:32 PDT 2025


================
@@ -341,15 +358,126 @@ struct __optional_destruct_base<_Tp, true> {
       __engaged_ = false;
     }
   }
+
+  _LIBCPP_HIDE_FROM_ABI constexpr bool has_value() const noexcept { return this->__engaged_; }
+};
+
+#ifdef _LIBCPP_ABI_COOPERATIVE_OPTIONAL
+template <class _Tp>
+struct __optional_destruct_base<_Tp, false, true> {
+  using value_type = _Tp;
+  static_assert(is_object_v<value_type>, "instantiation of optional with a non-object type is undefined behavior");
----------------
frederick-vs-ja wrote:

There's mandatory error (ill-formedness) but not UB, as implied by the member function signatures.

https://github.com/llvm/llvm-project/pull/93672


More information about the libcxx-commits mailing list