Re: [PATCH] libstdc++/92124 for associative containers

2020-01-06 Thread Jonathan Wakely

On 03/01/20 22:04 +0100, François Dumont wrote:

This is the patch to extend PR 92124 to the associative containers.

As it is pretty simple I thought it could maybe go in now.

I also think that the existing 92124 tests are not really testing what 
they should with the move assignment operators noexcept qualified, no 
?


    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/deque/92124.cc
    (X::operator==(X&&)): Qualify noexcept(false).
    * testsuite/23_containers/forward_list/92124.cc: Likewise.
    * testsuite/23_containers/list/92124.cc: Likewise.
    * testsuite/23_containers/vector/92124.cc: Likewise.
    * testsuite/23_containers/map/92124.cc: New.
    * testsuite/23_containers/set/92124.cc: New.

Tested under linux x86_64.

François




diff --git a/libstdc++-v3/include/bits/stl_tree.h 
b/libstdc++-v3/include/bits/stl_tree.h
index 12ba3181dd9..9339011e872 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(__cval);
- return __roan(std::move_if_noexcept(__val));
+ return __roan(std::move(__val));


This part is OK and so is the new test.


};
  _M_root() = _M_copy(__x, __lbd);
  __x.clear();
diff --git a/libstdc++-v3/testsuite/23_containers/deque/92124.cc 
b/libstdc++-v3/testsuite/23_containers/deque/92124.cc
index 0bdfcb70dcf..ea16d415a49 100644
--- a/libstdc++-v3/testsuite/23_containers/deque/92124.cc
+++ b/libstdc++-v3/testsuite/23_containers/deque/92124.cc
@@ -30,7 +30,7 @@ struct X {
// Tracking calls to assignment functions
X& operator=(const X&) { throw 1; }

-X& operator=(X&&) noexcept(true) { return *this; }
+X& operator=(X&&) noexcept(false) { return *this; }


These changes don't seem to be needed. Is there a reason to change it?



[PATCH] libstdc++/92124 for associative containers

2020-01-03 Thread François Dumont

This is the patch to extend PR 92124 to the associative containers.

As it is pretty simple I thought it could maybe go in now.

I also think that the existing 92124 tests are not really testing what 
they should with the move assignment operators noexcept qualified, no ?


    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/deque/92124.cc
    (X::operator==(X&&)): Qualify noexcept(false).
    * testsuite/23_containers/forward_list/92124.cc: Likewise.
    * testsuite/23_containers/list/92124.cc: Likewise.
    * testsuite/23_containers/vector/92124.cc: Likewise.
    * testsuite/23_containers/map/92124.cc: New.
    * testsuite/23_containers/set/92124.cc: New.

Tested under linux x86_64.

François

diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h
index 12ba3181dd9..9339011e872 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(__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/deque/92124.cc b/libstdc++-v3/testsuite/23_containers/deque/92124.cc
index 0bdfcb70dcf..ea16d415a49 100644
--- a/libstdc++-v3/testsuite/23_containers/deque/92124.cc
+++ b/libstdc++-v3/testsuite/23_containers/deque/92124.cc
@@ -30,7 +30,7 @@ struct X {
 // Tracking calls to assignment functions
 X& operator=(const X&) { throw 1; }
 
-X& operator=(X&&) noexcept(true) { return *this; }
+X& operator=(X&&) noexcept(false) { return *this; }
 };
 
 void
diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc b/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc
index 3e1b7ab3421..4d037f3a08f 100644
--- a/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc
+++ b/libstdc++-v3/testsuite/23_containers/forward_list/92124.cc
@@ -30,7 +30,7 @@ struct X {
 // Tracking calls to assignment functions
 X& operator=(const X&) { throw 1; }
 
-X& operator=(X&&) noexcept(true) { return *this; }
+X& operator=(X&&) noexcept(false) { return *this; }
 };
 
 void
diff --git a/libstdc++-v3/testsuite/23_containers/list/92124.cc b/libstdc++-v3/testsuite/23_containers/list/92124.cc
index f9f2ed2e76f..49b74cab7e5 100644
--- a/libstdc++-v3/testsuite/23_containers/list/92124.cc
+++ b/libstdc++-v3/testsuite/23_containers/list/92124.cc
@@ -30,7 +30,7 @@ struct X {
 // Tracking calls to assignment functions
 X& operator=(const X&) { throw 1; }
 
-X& operator=(X&&) noexcept(true) { return *this; }
+X& operator=(X&&) noexcept(false) { return *this; }
 };
 
 void
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 000..177c9d7abe9
--- /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
+// .
+
+// { dg-do run { target c++11 } }
+
+#include 
+#include 
+
+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, false>;
+  A a1(1), a2(2);
+  std::map, 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 000..95a2e9ce518
--- /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
+//