From f74912779b6c45d42c0a09821ad7bad0ae99e8c4 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 24 Jan 2014 20:08:20 +0000 Subject: [PATCH] re PR libstdc++/59548 (Abort after copying std::unordered_map in debug mode) PR libstdc++/59548 * include/debug/safe_base.h (_Safe_sequence_base): Define copy constructor to prevent it being implicitly defined as deleted, but do not copy anything. * include/debug/safe_unordered_base.h (_Safe_unordered_container_base): Define copy and move constructors similar to _Safe_sequence_base's. * testsuite/23_containers/unordered_map/59548.cc: New. From-SVN: r207059 --- libstdc++-v3/ChangeLog | 10 ++++++ libstdc++-v3/include/debug/safe_base.h | 3 ++ .../include/debug/safe_unordered_base.h | 12 ++++++- .../23_containers/unordered_map/59548.cc | 34 +++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_map/59548.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 211f7317131..30e4f22b8c8 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2014-01-24 Jonathan Wakely + + PR libstdc++/59548 + * include/debug/safe_base.h (_Safe_sequence_base): Define copy + constructor to prevent it being implicitly defined as deleted, but + do not copy anything. + * include/debug/safe_unordered_base.h (_Safe_unordered_container_base): + Define copy and move constructors similar to _Safe_sequence_base's. + * testsuite/23_containers/unordered_map/59548.cc: New. + 2014-01-23 Bernhard Reutner-Fischer Steve Ellcey diff --git a/libstdc++-v3/include/debug/safe_base.h b/libstdc++-v3/include/debug/safe_base.h index 4b1d082d264..631ac773ddb 100644 --- a/libstdc++-v3/include/debug/safe_base.h +++ b/libstdc++-v3/include/debug/safe_base.h @@ -193,6 +193,9 @@ namespace __gnu_debug { } #if __cplusplus >= 201103L + _Safe_sequence_base(const _Safe_sequence_base&) noexcept + : _Safe_sequence_base() { } + _Safe_sequence_base(_Safe_sequence_base&& __x) noexcept : _Safe_sequence_base() { _M_swap(__x); } diff --git a/libstdc++-v3/include/debug/safe_unordered_base.h b/libstdc++-v3/include/debug/safe_unordered_base.h index 9cde781364c..bbb274f34e4 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 00000000000..1e81bb74110 --- /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 +// . + +// libstdc++/59548 + +#include + +int main() +{ + std::unordered_map foo{ {0,1} }; + auto i = foo.begin(); + { + auto bar = foo; + } + return i->first; +}