[libcxx-commits] [libcxx] [libc++] Implement P2988R12: `std::optional<T&>` (PR #155202)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sun Oct 26 02:37:18 PDT 2025


================
@@ -221,6 +221,24 @@ TEST_CONSTEXPR_CXX20 bool test_empty_emplace() {
   return true;
 }
 
+#if TEST_STD_VER >= 26
+template <class T, std::remove_reference_t<T> _Val>
+constexpr bool test_ref() {
+  using Opt = std::optional<T&>;
+  T t{_Val};
+  {
+    Opt opt;
+    auto& v = opt.emplace(t);
+    static_assert(std::is_same_v<T&, decltype(v)>, "");
----------------
frederick-vs-ja wrote:

```suggestion
    static_assert(std::is_same_v<T&, decltype(v)>);
```

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


More information about the libcxx-commits mailing list