[libcxx-commits] [libcxx] [libc++] Strengthen optional value constructor noexcept (PR #202765)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 10 07:53:06 PDT 2026


================
@@ -984,21 +984,13 @@ public:
       : __base(in_place, __il, std::forward<_Args>(__args)...) {}
 
   template <class _Up = _Tp, enable_if_t<_CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>(), int> = 0>
-  _LIBCPP_HIDE_FROM_ABI constexpr optional(_Up&& __v)
-#    if _LIBCPP_STD_VER >= 26
-      noexcept(is_lvalue_reference_v<_Tp> && is_nothrow_constructible_v<_Tp&, _Up>)
-#    endif
-      : __base(in_place, std::forward<_Up>(__v)) {
-  }
+  _LIBCPP_HIDE_FROM_ABI constexpr optional(_Up&& __v) noexcept(is_nothrow_constructible_v<_Tp, _Up>)
+      : __base(in_place, std::forward<_Up>(__v)) {}
 
   template <class _Up                                                                        = remove_cv_t<_Tp>,
             enable_if_t<_CheckOptionalArgsCtor<_Up>::template __enable_explicit<_Up>(), int> = 0>
-  _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Up&& __v)
-#    if _LIBCPP_STD_VER >= 26
-      noexcept(is_lvalue_reference_v<_Tp> && is_nothrow_constructible_v<_Tp&, _Up>)
-#    endif
-      : __base(in_place, std::forward<_Up>(__v)) {
-  }
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Up&& __v) noexcept(is_nothrow_constructible_v<_Tp, _Up>)
----------------
ldionne wrote:

When we strengthen a `noexcept`, we recently started adding `// strengthened` comments in the code, like some other implementations do (we started in `<expected>`). Let's do that here.

```suggestion
  _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_Up&& __v) noexcept(is_nothrow_constructible_v<_Tp, _Up>) // strengthened
```

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


More information about the libcxx-commits mailing list