On 24/01/14 20:08 +0000, Jonathan Wakely wrote:
The debug-mode container base classes need copy constructors that
zero-init their members rather than copy them from the source.
_Safe_unordered_container_base also needs its move constructor to be
non-throwing to fix some FAILs for the PR 55043 tests.
Tested x86_64-linux, normal and debug modes, committed to trunk.
I also want to fix this on the branches once I've finished fixing 4.9
regressions.
Here's a smaller version of the trunk patch which I'm committing to
the 4.8 branch.
Tested x86_64-linux.
(Aside: I wish "make check-debug" didn't take so long, and why does
that target put conformance.exp in the RUNTESTFLAGS explicitly, so you
can't do RUNTESTFLAGS=conformance.exp=23_containers/unordered_*" to
re-run just a subset of the tests?)
commit 39fadff8d22cf549968a2df4117111de4173db2f
Author: Jonathan Wakely <jwak...@redhat.com>
Date: Wed Mar 26 19:33:35 2014 +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.
diff --git a/libstdc++-v3/include/debug/safe_unordered_base.h
b/libstdc++-v3/include/debug/safe_unordered_base.h
index 23026cb..35ce08b 100644
--- a/libstdc++-v3/include/debug/safe_unordered_base.h
+++ b/libstdc++-v3/include/debug/safe_unordered_base.h
@@ -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
index 0000000..1e81bb7
--- /dev/null
+++ b/libstdc++-v3/testsuite/23_containers/unordered_map/59548.cc
@@ -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;
+}