[libcxx-commits] [libcxx] [libc++] Fix make_from_tuple for reference types (PR #220966)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 3 08:13:19 PDT 2026


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/220966

#215067 refactored `make_from_tuple`, which introduced a regression when trying to construct reference types with it.


>From 410cada29fca1439dc590cfdaca027ac58fc1e99 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Thu, 3 Sep 2026 17:11:44 +0200
Subject: [PATCH] [libc++] Fix make_from_tuple for reference types

---
 libcxx/include/tuple                                         | 2 +-
 .../tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp   | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index 03ff3ef36ee1a..9726c97746048 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -1398,7 +1398,7 @@ make_from_tuple(_Tuple&& __tuple) noexcept(__can_nothrow_make_from_tuple_v<_Tp,
                   "Attempted construction of reference element binds to a temporary whose lifetime has ended");
   }
 #      endif // _LIBCPP_STD_VER >= 23
-  return std::apply([]<class... _Args>(_Args&&... __args) { return _Tp(std::forward<_Args>(__args)...); },
+  return std::apply([]<class... _Args>(_Args&&... __args) -> _Tp { return _Tp(std::forward<_Args>(__args)...); },
                     std::forward<_Tuple>(__tuple));
 }
 
diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp
index 67281ea1864a5..b9a15b8729ff4 100644
--- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp
+++ b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.apply/make_from_tuple.pass.cpp
@@ -255,5 +255,10 @@ int main(int, char**)
     test_perfect_forwarding();
     test_noexcept();
 
+  { // Test that constructing a T& returns the same object
+    int i;
+    assert(&std::make_from_tuple<const int&>(std::tuple<int&>(i)) == &i);
+  }
+
   return 0;
 }



More information about the libcxx-commits mailing list