+2010-01-08 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR libstdc++/42573
+ * include/bits/allocator.h (struct __shrink_to_fit): Add.
+ * include/bits/stl_deque.h (deque<>::shrink_to_fit): Add.
+ * include/bits/stl_vector.h (vector<>::shrink_to_fit): Likewise.
+ * include/bits/stl_bvector.h (vector<bool>::shrink_to_fit): Likewise.
+ * include/bits/basic_string.h (basic_string<>::shrink_to_fit):
+ Likewise.
+ * include/ext/vstring.h (__versa_string<>::shrink_to_fit): Likewise.
+ * include/debug/deque: Add corresponding using declaration.
+ * include/debug/vector: Likewise.
+ * include/debug/string: Likewise.
+ * include/profile/deque: Likewise.
+ * include/profile/vector: Likewise.
+ * config/abi/pre/gnu.ver: Export new symbols.
+ * testsuite/23_containers/deque/capacity/shrink_to_fit.cc: New.
+ * testsuite/23_containers/vector/capacity/shrink_to_fit.cc: Likewise.
+ * testsuite/21_strings/basic_string/capacity/char/shrink_to_fit.cc:
+ Likewise.
+ * testsuite/21_strings/basic_string/capacity/wchar_t/shrink_to_fit.cc:
+ Likewise.
+ * testsuite/ext/vstring/capacity/shrink_to_fit.cc: Likewise.
+ * testsuite/23_containers/deque/requirements/dr438/assign_neg.cc:
+ Adjust dg-error line number.
+ * testsuite/23_containers/deque/requirements/dr438/insert_neg.cc:
+ Likewise.
+ * testsuite/23_containers/deque/requirements/dr438/
+ constructor_1_neg.cc: Likewise.
+ * testsuite/23_containers/deque/requirements/dr438/
+ constructor_2_neg.cc: Likewise.
+ * testsuite/23_containers/vector/requirements/dr438/assign_neg.cc:
+ Adjust dg-error line number.
+ * testsuite/23_containers/vector/requirements/dr438/insert_neg.cc:
+ Likewise.
+ * testsuite/23_containers/vector/requirements/dr438/
+ constructor_1_neg.cc: Likewise.
+ * testsuite/23_containers/vector/requirements/dr438/
+ constructor_2_neg.cc: Likewise.
+
2010-01-07 Benjamin Kosnik <bkoz@redhat.com>
* doc/xml/manual/evolution.xml: Fix typos, update.
_ZNSs18_S_construct_aux_2*;
_ZNSbIwSt11char_traitsIwESaIwEE18_S_construct_aux_2*;
+ # string|wstring shrink_to_fit member function
+ _ZNSs13shrink_to_fitEv;
+ _ZNSbIwSt11char_traitsIwESaIwEE13shrink_to_fitEv;
+
_ZSt25__throw_bad_function_callv;
# std::time_get::_M_extract_wday_or_month
// Allocators -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
{ return __one != __two; }
};
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ // A very basic implementation for now. In general we have to wait for
+ // the availability of the infrastructure described in N2983: we should
+ // try when either T has a move constructor which cannot throw or T is
+ // CopyContructible.
+ // NB: This code doesn't properly belong here, we should find a more
+ // suited place common to std::vector and std::deque.
+ template<typename _Tp,
+ bool = __has_trivial_copy(typename _Tp::value_type)>
+ struct __shrink_to_fit
+ { static void _S_do_it(_Tp&) { } };
+
+ template<typename _Tp>
+ struct __shrink_to_fit<_Tp, true>
+ {
+ static void
+ _S_do_it(_Tp& __v)
+ {
+ try
+ { _Tp(__v).swap(__v); }
+ catch(...) { }
+ }
+ };
+#endif
+
_GLIBCXX_END_NAMESPACE
#endif
length() const
{ return _M_rep()->_M_length; }
- /// Returns the size() of the largest possible %string.
+ /// Returns the size() of the largest possible %string.
size_type
max_size() const
{ return _Rep::_S_max_size; }
resize(size_type __n)
{ this->resize(__n, _CharT()); }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ /// A non-binding request to reduce capacity() to size().
+ void
+ shrink_to_fit()
+ {
+ try
+ { reserve(0); }
+ catch(...)
+ { }
+ }
+#endif
+
/**
* Returns the total number of characters that the %string can hold
* before needing to allocate more memory.
// vector<bool> specialization -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
assign(initializer_list<bool> __l)
{ this->assign(__l.begin(), __l.end()); }
#endif
-
+
iterator
begin()
{ return this->_M_impl._M_start; }
insert(end(), __new_size - size(), __x);
}
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ void
+ shrink_to_fit()
+ { std::__shrink_to_fit<vector>::_S_do_it(*this); }
+#endif
+
void
flip()
{
// Deque implementation -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
insert(this->_M_impl._M_finish, __new_size - __len, __x);
}
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ /** A non-binding request to reduce memory use. */
+ void
+ shrink_to_fit()
+ { std::__shrink_to_fit<deque>::_S_do_it(*this); }
+#endif
+
/**
* Returns true if the %deque is empty. (Thus begin() would
* equal end().)
// Vector implementation -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
insert(end(), __new_size - size(), __x);
}
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ /** A non-binding request to reduce capacity() to size(). */
+ void
+ shrink_to_fit()
+ { std::__shrink_to_fit<vector>::_S_do_it(*this); }
+#endif
+
/**
* Returns the total number of elements that the %vector can
* hold before needing to allocate more memory.
// Debugging deque implementation -*- C++ -*-
-// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
this->_M_invalidate_all();
}
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ using _Base::shrink_to_fit;
+#endif
+
using _Base::empty;
// element access:
// Debugging string implementation -*- C++ -*-
-// Copyright (C) 2003, 2005, 2006, 2009
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
resize(size_type __n)
{ this->resize(__n, _CharT()); }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ using _Base::shrink_to_fit;
+#endif
+
using _Base::capacity;
using _Base::reserve;
// Debugging vector implementation -*- C++ -*-
-// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
this->_M_invalidate_all();
}
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ using _Base::shrink_to_fit;
+#endif
+
size_type
capacity() const
{
// Versatile string -*- C++ -*-
-// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
+// 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
class __versa_string
: private _Base<_CharT, _Traits, _Alloc>
{
- typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
+ typedef _Base<_CharT, _Traits, _Alloc> __vstring_base;
typedef typename __vstring_base::_CharT_alloc_type _CharT_alloc_type;
// Types:
resize(size_type __n)
{ this->resize(__n, _CharT()); }
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ /// A non-binding request to reduce capacity() to size().
+ void
+ shrink_to_fit()
+ {
+ try
+ { this->reserve(0); }
+ catch(...)
+ { }
+ }
+#endif
+
/**
* Returns the total number of characters that the %string can
* hold before needing to allocate more memory.
// Profiling deque implementation -*- C++ -*-
-// Copyright (C) 2009 Free Software Foundation, Inc.
+// Copyright (C) 2009, 2010 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
_Base::resize(__sz, __c);
}
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ using _Base::shrink_to_fit;
+#endif
+
using _Base::empty;
// element access:
// Profiling vector implementation -*- C++ -*-
-// Copyright (C) 2009 Free Software Foundation, Inc.
+// Copyright (C) 2009, 2010 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
_Base::resize(__sz, __c);
}
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+ using _Base::shrink_to_fit;
+#endif
+
using _Base::empty;
// element access:
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// 2010-01-08 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 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 Pred 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/>.
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// libstdc++/42573
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::string s(100, 'a');
+ s.push_back('b');
+ s.push_back('b');
+ VERIFY( s.size() < s.capacity() );
+ s.shrink_to_fit();
+ VERIFY( s.size() == s.capacity() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// 2010-01-08 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 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 Pred 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/>.
+
+#include <string>
+#include <testsuite_hooks.h>
+
+// libstdc++/42573
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::wstring s(100, L'a');
+ s.push_back(L'b');
+ s.push_back(L'b');
+ VERIFY( s.size() < s.capacity() );
+ s.shrink_to_fit();
+ VERIFY( s.size() == s.capacity() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// 2010-01-08 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 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 Pred 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/>.
+
+#include <vector>
+#include <testsuite_hooks.h>
+
+// libstdc++/42573
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::vector<int> d(100);
+ d.push_back(1);
+ d.push_back(1);
+ // VERIFY( d.size() < d.capacity() );
+ d.shrink_to_fit();
+ // VERIFY( d.size() == d.capacity() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
// 2007-04-27 Paolo Carlini <pcarlini@suse.de>
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation
+// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation
//
// 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
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1568 }
+// { dg-error "no matching" "" { target *-*-* } 1575 }
// { dg-excess-errors "" }
#include <deque>
// 2007-04-27 Paolo Carlini <pcarlini@suse.de>
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation
+// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation
//
// 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
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1507 }
+// { dg-error "no matching" "" { target *-*-* } 1514 }
// { dg-excess-errors "" }
#include <deque>
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1507 }
+// { dg-error "no matching" "" { target *-*-* } 1514 }
// { dg-excess-errors "" }
#include <deque>
// 2007-04-27 Paolo Carlini <pcarlini@suse.de>
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation
+// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation
//
// 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
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1652 }
+// { dg-error "no matching" "" { target *-*-* } 1659 }
// { dg-excess-errors "" }
#include <deque>
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// 2010-01-08 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 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 Pred 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/>.
+
+#include <vector>
+#include <testsuite_hooks.h>
+
+// libstdc++/42573
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::vector<int> v(100);
+ v.push_back(1);
+ v.push_back(1);
+ VERIFY( v.size() < v.capacity() );
+ v.shrink_to_fit();
+ VERIFY( v.size() == v.capacity() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
// 2007-04-27 Paolo Carlini <pcarlini@suse.de>
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation
+// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation
//
// 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
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1047 }
+// { dg-error "no matching" "" { target *-*-* } 1054 }
// { dg-excess-errors "" }
#include <vector>
// 2007-04-27 Paolo Carlini <pcarlini@suse.de>
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation
+// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation
//
// 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
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 987 }
+// { dg-error "no matching" "" { target *-*-* } 994 }
// { dg-excess-errors "" }
#include <vector>
// 2007-04-27 Paolo Carlini <pcarlini@suse.de>
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation
+// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation
//
// 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
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 987 }
+// { dg-error "no matching" "" { target *-*-* } 994 }
// { dg-excess-errors "" }
#include <vector>
// 2007-04-27 Paolo Carlini <pcarlini@suse.de>
-// Copyright (C) 2007, 2008, 2009 Free Software Foundation
+// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation
//
// 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
// <http://www.gnu.org/licenses/>.
// { dg-do compile }
-// { dg-error "no matching" "" { target *-*-* } 1088 }
+// { dg-error "no matching" "" { target *-*-* } 1095 }
// { dg-excess-errors "" }
#include <vector>
--- /dev/null
+// { dg-options "-std=gnu++0x" }
+
+// 2010-01-08 Paolo Carlini <paolo.carlini@oracle.com>
+
+// Copyright (C) 2010 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 Pred 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/>.
+
+#include <ext/vstring.h>
+#include <testsuite_hooks.h>
+
+// libstdc++/42573
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ __gnu_cxx::__vstring vs(100, 'a');
+ vs.push_back('b');
+ vs.push_back('b');
+ VERIFY( vs.size() < vs.capacity() );
+ vs.shrink_to_fit();
+ VERIFY( vs.size() == vs.capacity() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}