[PATCH v6 2/2] libstdc++: Implement const copy-assignment for tuple<> [PR119721]

Jonathan Wakely jwakely@redhat.com
Wed Oct 29 15:54:40 GMT 2025


On Mon, 27 Oct 2025 at 15:11 +0100, Tomasz Kamiński wrote:
>This patch completes the implementation of P2321R2, giving tuple proper proxy
>reference semantics.
>
>The assignment operator is implemented as a template constrained to accept only
>tuple<>. Consequently, the language does not consider it a copy assignment
>operator, which prevents tuple<> from losing its trivially copyable status.
>
>The _Tuple template parameter is defaulted, ensuring the constructor remains

s/constructor/operator/

>a viable candidate for assignment with an empty brace-init list.
>
>	PR libstdc++/119721
>
>libstdc++-v3/ChangeLog:
>
>	* include/std/tuple (tuple<>::operator=(const _Tuple&) const)
>	[__cpp_lib_ranges_zip]: Define.
>	* testsuite/23_containers/tuple/cons/119721.cc: Test const
>	assigment.

"assignment"


OK for trunk with those changes.


>---
>v6:
> - add const assigment tuple test to this patch
> - test return type in const-assigment tests
>
> libstdc++-v3/include/std/tuple                |  5 +++++
> .../23_containers/tuple/cons/119721.cc        | 20 ++++++++++++++-----
> 2 files changed, 20 insertions(+), 5 deletions(-)
>
>diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
>index 28a99ead499..c701164c84a 100644
>--- a/libstdc++-v3/include/std/tuple
>+++ b/libstdc++-v3/include/std/tuple
>@@ -1996,6 +1996,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>       void swap(tuple&) noexcept { /* no-op */ }
>
> #if __cpp_lib_ranges_zip // >= C++23
>+      template<same_as<tuple> _Tuple = tuple>
>+      constexpr const tuple&
>+      operator=(const _Tuple&) const noexcept
>+      { return *this; }
>+
>       constexpr void swap(const tuple&) const noexcept
>       { /* no-op */ }
> #endif
>diff --git a/libstdc++-v3/testsuite/23_containers/tuple/cons/119721.cc b/libstdc++-v3/testsuite/23_containers/tuple/cons/119721.cc
>index 240f1a5e8d7..1d152386fb7 100644
>--- a/libstdc++-v3/testsuite/23_containers/tuple/cons/119721.cc
>+++ b/libstdc++-v3/testsuite/23_containers/tuple/cons/119721.cc
>@@ -69,12 +69,22 @@ test04()
> {
>   std::array<int, 0> a{};
>   const std::tuple<> t1;
>-
>+
>   // Const assignment from array
>-  t1 = a;
>-  t1 = std::move(a);
>-
>-  VERIFY( t1 == a );
>+  std::tuple<> t2;
>+  const std::tuple<>& r1 = (t1 = t2);
>+  VERIFY( &r1 == &t1 );
>+  const std::tuple<>& r2 = (t1 = std::move(t2));
>+  VERIFY( &r2 == &t1 );
>+
>+  const std::tuple<>& r3 = (t1 = {});
>+  VERIFY( &r3 == &t1 );
>+
>+  // Const assignment from array
>+  const std::tuple<>& r4 = (t1 = a);
>+  VERIFY( &r4 == &t1 );
>+  const std::tuple<>& r5 = (t1 = std::move(a));
>+  VERIFY( &r5 == &t1 );
> }
>
> void
>-- 
>2.51.0
>
>



More information about the Libstdc++ mailing list