public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Fix move construction of std::tuple with array elements [PR101960]
@ 2021-08-19 12:04 Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-08-19 12:04 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 688 bytes --]

An array member cannot be direct-initialized in a ctor-initializer-list,
so use the base class' move constructor, which does the right thing for
both arrays and non-arrays.

This constructor could be defaulted, but that would make it trivial for
some specializations, which would change the argument passing ABI. Do
that for the versioned namespace only.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	PR libstdc++/101960
	* include/std/tuple (_Tuple_impl(_Tuple_impl&&)): Use base
	class' move constructor. Define as defaulted for versioned
	namespace.
	* testsuite/20_util/tuple/cons/101960.cc: New test.

Tested powerpc64le-linux. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2064 bytes --]

commit 0187e0d7360f327f88d8b2294668669306ae4630
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 19 11:48:40 2021

    libstdc++: Fix move construction of std::tuple with array elements [PR101960]
    
    An array member cannot be direct-initialized in a ctor-initializer-list,
    so use the base class' move constructor, which does the right thing for
    both arrays and non-arrays.
    
    This constructor could be defaulted, but that would make it trivial for
    some specializations, which would change the argument passing ABI. Do
    that for the versioned namespace only.
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/101960
            * include/std/tuple (_Tuple_impl(_Tuple_impl&&)): Use base
            class' move constructor. Define as defaulted for versioned
            namespace.
            * testsuite/20_util/tuple/cons/101960.cc: New test.

diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 1292aee45c0..f082ccb8a3b 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -438,11 +438,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       // 2729. Missing SFINAE on std::pair::operator=
       _Tuple_impl& operator=(const _Tuple_impl&) = delete;
 
+#if _GLIBCXX_INLINE_VERSION
+      _Tuple_impl(_Tuple_impl&&) = default;
+#else
       constexpr
       _Tuple_impl(_Tuple_impl&& __in)
       noexcept(is_nothrow_move_constructible<_Head>::value)
-      : _Base(std::forward<_Head>(_M_head(__in)))
+      : _Base(static_cast<_Base&&>(__in))
       { }
+#endif
 
       template<typename _UHead>
 	constexpr
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/101960.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/101960.cc
new file mode 100644
index 00000000000..f14604cdc69
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/tuple/cons/101960.cc
@@ -0,0 +1,4 @@
+// { dg-do compile { target c++11 } }
+#include <tuple>
+std::tuple<int[1]> t;
+auto tt = std::move(t); // PR libstdc++/101960

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [committed] libstdc++: Fix move construction of std::tuple with array elements [PR101960]
@ 2021-10-12 15:50 Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-10-12 15:50 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 675 bytes --]

The r12-3022 commit only fixed the case where an array is the last
element of the tuple. This fixes the other cases too. We can just define
the move constructor as defaulted, which does the right thing. Changing
the move constructor to be trivial would be an ABI break, but since the
last base class still has a non-trivial move constructor, defining the
derived ones as defaulted doesn't change anything.

libstdc++-v3/ChangeLog:

	PR libstdc++/101960
	* include/std/tuple (_Tuple_impl(_Tuple_impl&&)): Define as
	defauled.
	* testsuite/20_util/tuple/cons/101960.cc: Check tuples with
	array elements before the last element.

Tested powerpc64le-linux. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2269 bytes --]

commit 7481021364e75ba583972e15ed421a53988368ea
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Oct 12 15:09:50 2021

    libstdc++: Fix move construction of std::tuple with array elements [PR101960]
    
    The r12-3022 commit only fixed the case where an array is the last
    element of the tuple. This fixes the other cases too. We can just define
    the move constructor as defaulted, which does the right thing. Changing
    the move constructor to be trivial would be an ABI break, but since the
    last base class still has a non-trivial move constructor, defining the
    derived ones as defaulted doesn't change anything.
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/101960
            * include/std/tuple (_Tuple_impl(_Tuple_impl&&)): Define as
            defauled.
            * testsuite/20_util/tuple/cons/101960.cc: Check tuples with
            array elements before the last element.

diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 94a4f0afd31..aaee0b8826a 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -298,13 +298,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       // 2729. Missing SFINAE on std::pair::operator=
       _Tuple_impl& operator=(const _Tuple_impl&) = delete;
 
-      constexpr
-      _Tuple_impl(_Tuple_impl&& __in)
-      noexcept(__and_<is_nothrow_move_constructible<_Head>,
-		      is_nothrow_move_constructible<_Inherited>>::value)
-      : _Inherited(std::move(_M_tail(__in))),
-	_Base(std::forward<_Head>(_M_head(__in)))
-      { }
+      _Tuple_impl(_Tuple_impl&&) = default;
 
       template<typename... _UElements>
 	constexpr
diff --git a/libstdc++-v3/testsuite/20_util/tuple/cons/101960.cc b/libstdc++-v3/testsuite/20_util/tuple/cons/101960.cc
index f14604cdc69..42d17b182ed 100644
--- a/libstdc++-v3/testsuite/20_util/tuple/cons/101960.cc
+++ b/libstdc++-v3/testsuite/20_util/tuple/cons/101960.cc
@@ -1,4 +1,13 @@
 // { dg-do compile { target c++11 } }
 #include <tuple>
+
+// PR libstdc++/101960
+
 std::tuple<int[1]> t;
-auto tt = std::move(t); // PR libstdc++/101960
+auto tt = std::move(t);
+
+std::tuple<int[1], int> t2;
+auto tt2 = std::move(t2);
+
+std::tuple<int[1], int[2], int[3]> t3;
+auto tt3 = std::move(t3);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-12 15:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19 12:04 [committed] libstdc++: Fix move construction of std::tuple with array elements [PR101960] Jonathan Wakely
2021-10-12 15:50 Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).