]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/59548 (Abort after copying std::unordered_map in debug mode)
authorJonathan Wakely <jwakely@redhat.com>
Wed, 26 Mar 2014 19:41:16 +0000 (19:41 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 26 Mar 2014 19:41:16 +0000 (19:41 +0000)
PR libstdc++/59548
* include/debug/safe_unordered_base.h (_Safe_unordered_container_base):
Define copy and move constructors that handle iterators correctly.
* testsuite/23_containers/unordered_map/59548.cc: New.

From-SVN: r208850

libstdc++-v3/ChangeLog
libstdc++-v3/include/debug/safe_unordered_base.h
libstdc++-v3/testsuite/23_containers/unordered_map/59548.cc [new file with mode: 0644]

index a194b288a16563e66e72a1962cb78145e7c433b8..26ad5e00694cc9230e09aba8d124d2c7cdf86c7d 100644 (file)
@@ -1,3 +1,10 @@
+2014-03-26  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/59548
+       * include/debug/safe_unordered_base.h (_Safe_unordered_container_base):
+       Define copy and move constructors that handle iterators correctly.
+       * testsuite/23_containers/unordered_map/59548.cc: New.
+
 2014-03-25  Jonathan Wakely  <jwakely@redhat.com>
 
        PR libstdc++/60658
index 23026cb43b43588b83d305af19b52f5a7d6c6eac..35ce08b1ff2f0443553472c623f35e56e4d961fe 100644 (file)
@@ -133,9 +133,19 @@ namespace __gnu_debug
   protected:
     // Initialize with a version number of 1 and no iterators
     _Safe_unordered_container_base()
-    : _M_local_iterators(0), _M_const_local_iterators(0)
+    : _M_local_iterators(nullptr), _M_const_local_iterators(nullptr)
     { }
 
+    // Initialize with a version number of 1 and no iterators
+    _Safe_unordered_container_base(const _Safe_unordered_container_base&)
+    noexcept
+    : _Safe_unordered_container_base() { }
+
+    _Safe_unordered_container_base(_Safe_unordered_container_base&& __x)
+    noexcept
+    : _Safe_unordered_container_base()
+    { this->_M_swap(__x); }
+
     /** Notify all iterators that reference this container that the
        container is being destroyed. */
     ~_Safe_unordered_container_base()
diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/59548.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/59548.cc
new file mode 100644 (file)
index 0000000..1e81bb7
--- /dev/null
@@ -0,0 +1,34 @@
+// { dg-options "-std=gnu++11" }
+// { dg-do compile }
+// { dg-require-debug-mode "" }
+
+// Copyright (C) 2014 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/>.
+
+// libstdc++/59548
+
+#include <unordered_map>
+
+int main()
+{
+  std::unordered_map<int,int> foo{ {0,1} };
+  auto i = foo.begin();
+  {
+    auto bar = foo;
+  }
+  return i->first;
+}