[gcc/devel/gccgo] PR libstdc++/92124 fix incorrect container move assignment

Ian Lance Taylor ian@gcc.gnu.org
Thu Jan 23 00:04:00 GMT 2020


https://gcc.gnu.org/g:6af8819be1e09fa2035248eba7fb320350ec14ab

commit 6af8819be1e09fa2035248eba7fb320350ec14ab
Author: François Dumont <fdumont@gcc.gnu.org>
Date:   Tue Jan 7 21:01:37 2020 +0000

    PR libstdc++/92124 fix incorrect container move assignment
    
    	* include/bits/stl_tree.h
    	(_Rb_tree<>::_M_move_assign(_Rb_tree&, false_type)): Replace
    	std::move_if_noexcept by std::move.
    	* testsuite/23_containers/map/92124.cc: New.
    	* testsuite/23_containers/set/92124.cc: New.
    
    From-SVN: r279967

Diff:
---
 libstdc++-v3/ChangeLog                            |  9 +++
 libstdc++-v3/include/bits/stl_tree.h              |  2 +-
 libstdc++-v3/testsuite/23_containers/map/92124.cc | 58 ++++++++++++++++++
 libstdc++-v3/testsuite/23_containers/set/92124.cc | 73 +++++++++++++++++++++++
 4 files changed, 141 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 1e46178..4aae9fa 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,12 @@
+2020-01-07  François Dumont  <fdumont@gcc.gnu.org>
+
+	PR libstdc++/92124
+	* include/bits/stl_tree.h
+	(_Rb_tree<>::_M_move_assign(_Rb_tree&, false_type)): Replace
+	std::move_if_noexcept by std::move.
+	* testsuite/23_containers/map/92124.cc: New.
+	* testsuite/23_containers/set/92124.cc: New.
+
 2020-01-06  Jonathan Wakely  <jwakely@redhat.com>
 
 	* include/std/stop_token (stop_token): Remove operator!= (LWG 3254).
diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h
index 12ba318..9339011 100644
--- a/libstdc++-v3/include/bits/stl_tree.h
+++ b/libstdc++-v3/include/bits/stl_tree.h
@@ -1695,7 +1695,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	    [&__roan](const value_type& __cval)
 	    {
 	      auto& __val = const_cast<value_type&>(__cval);
-	      return __roan(std::move_if_noexcept(__val));
+	      return __roan(std::move(__val));
 	    };
 	  _M_root() = _M_copy(__x, __lbd);
 	  __x.clear();
diff --git a/libstdc++-v3/testsuite/23_containers/map/92124.cc b/libstdc++-v3/testsuite/23_containers/map/92124.cc
new file mode 100644
index 0000000..177c9d7
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/map/92124.cc
@@ -0,0 +1,58 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++11 } }
+
+#include <map>
+#include <testsuite_allocator.h>
+
+struct X
+{
+  X() = default;
+  X(const X&)
+  { if (Throw) throw 1; }
+
+  // Move constructor might throw
+  X(X&&) noexcept(false) {}
+
+  // Tracking calls to assignment functions
+  X& operator=(const X&) { throw 1; }
+
+  X& operator=(X&&) noexcept(false) { return *this; }
+
+  static bool Throw;
+};
+
+bool X::Throw = false;
+
+void
+test01()
+{
+  using A = __gnu_test::propagating_allocator<std::pair<const int, X>, false>;
+  A a1(1), a2(2);
+  std::map<int, X, std::less<int>, A>
+    m1({ { 1, X() } }, a1),
+    m2({ { 2, X() } }, a2);
+  X::Throw = true;
+  m1 = std::move(m2);
+}
+
+int
+main()
+{
+  test01();
+}
diff --git a/libstdc++-v3/testsuite/23_containers/set/92124.cc b/libstdc++-v3/testsuite/23_containers/set/92124.cc
new file mode 100644
index 0000000..95a2e9c
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/set/92124.cc
@@ -0,0 +1,73 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-do run { target c++11 } }
+
+#include <set>
+#include <testsuite_allocator.h>
+
+struct X
+{
+  X(int i) noexcept(true) : _i(i) { }
+  X(const X& x) noexcept(false)
+  {
+    if (Throw) throw 0;
+    _i = x._i;
+  }
+
+  // Move constructor might throw
+  X(X&& x) noexcept(false)
+  {
+    _i = x._i;
+    x._i = -x._i;
+  }
+
+  // Tracking calls to assignment functions
+  X& operator=(const X&) { throw 1; }
+
+  X& operator=(X&& x) noexcept(false)
+  {
+    _i = x._i;
+    x._i = -x._i;
+    return *this;
+  }
+
+  bool
+  operator < (const X& x) const
+  { return _i < x._i; }
+
+  int _i;
+  static bool Throw;
+};
+
+bool X::Throw = false;
+
+void
+test01()
+{
+  using A = __gnu_test::propagating_allocator<X, false>;
+  A a1(1), a2(2);
+  std::set<X, std::less<X>, A> s1({ X(1) }, a1), s2({ X(2) }, a2);
+  X::Throw = true;
+  s1 = std::move(s2);
+}
+
+int
+main()
+{
+  test01();
+}



More information about the Libstdc++-cvs mailing list