[libcxx-commits] [libcxx] [libc++][NFC] Reduce workaround in a `in_place_t` constructor of `optional` (PR #174306)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jan 3 21:47:24 PST 2026


https://github.com/frederick-vs-ja updated https://github.com/llvm/llvm-project/pull/174306

>From 540fdee6c18d82057a736afe9a3013dc21d722a4 Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Sun, 4 Jan 2026 10:52:05 +0800
Subject: [PATCH] [libc++][NFC] Reduce workaround in a `in_place_t` ctor of
 `optional`

There used to be a bug of Clang on constraint computation that blocked
some usages of `optional<NestedClass>`. Workaround for the bug was added
by 86af6f5088b16c98e7033a6a5cf3c889c5d95e57.

It's verified that since LLVM 16, the regression test started to compile
with Clang with the workaround that added an additional template
parameter removed. However, until Clang 21, there was a still a bug that
affected constraints using variable templates. So the workaround is
reduced to just using `::value`.

In LLVM 23 we should be able to remove the whole workaround.
---
 libcxx/include/optional | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libcxx/include/optional b/libcxx/include/optional
index 568c86556d156..91f87ef081900 100644
--- a/libcxx/include/optional
+++ b/libcxx/include/optional
@@ -682,6 +682,7 @@ struct __is_std_optional<optional<_Tp>> : true_type {};
 template <class _Tp, class... _Args>
 inline constexpr bool __is_constructible_for_optional_v = is_constructible_v<_Tp, _Args...>;
 
+// TODO(LLVM 23): Remove this workaround.
 template <class _Tp, class... _Args>
 struct __is_constructible_for_optional : bool_constant<__is_constructible_for_optional_v<_Tp, _Args...>> {};
 
@@ -895,11 +896,9 @@ public:
   _LIBCPP_HIDE_FROM_ABI constexpr optional(optional&&)      = default;
   _LIBCPP_HIDE_FROM_ABI constexpr optional(nullopt_t) noexcept {}
 
-  template <
-      class _InPlaceT,
-      class... _Args,
-      enable_if_t<_And<_IsSame<_InPlaceT, in_place_t>, __is_constructible_for_optional<_Tp, _Args...>>::value, int> = 0>
-  _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(_InPlaceT, _Args&&... __args)
+  // TODO(LLVM 23): Use _v instead of ::value.
+  template <class... _Args, enable_if_t<__is_constructible_for_optional<_Tp, _Args...>::value, int> = 0>
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit optional(in_place_t, _Args&&... __args)
       : __base(in_place, std::forward<_Args>(__args)...) {}
 
   template <class _Up,
@@ -1013,7 +1012,8 @@ public:
     return *this;
   }
 
-  template <class... _Args, enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
+  // TODO(LLVM 23): Use _v instead of ::value.
+  template <class... _Args, enable_if_t<is_constructible<_Tp, _Args...>::value, int> = 0>
   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp& emplace(_Args&&... __args) {
     reset();
     this->__construct(std::forward<_Args>(__args)...);



More information about the libcxx-commits mailing list