From: Paolo Carlini Date: Mon, 6 Jun 2005 16:59:55 +0000 (+0000) Subject: [multiple changes] X-Git-Tag: misc/cutover-cvs2svn~2594 X-Git-Url: https://gcc.gnu.org/git/?a=commitdiff_plain;h=2fecaef4af7206fbae14906000e8c81007514706;p=gcc.git [multiple changes] 2005-06-06 Paolo Carlini Port from libstdcxx_so_7-branch: 2004-09-24 Paolo Carlini Jonathan Wakely * include/bits/stl_list.h (list::list(size_type, value_type, const allocator_type&): Implement according to the letter of the standard, i.e., don't use two overloads, not equivalent in case of non default constructible T. (list::resize(size_type, const value_type&)): Fix the signature: according to the standard the second argument is by value; also, don't use two overloads. * include/bits/list.tcc (list::resize(size_type, const value_type&)): Adjust consistently the signature. * include/bits/stl_deque.h (deque::deque(size_type, value_type, const allocator_type&)): Likewise. (deque::resize(size_type, const value_type&)): Likewise. * include/bits/stl_vector.h (vector::vector(size_type, value_type, const allocator_type&)): Likewise. (vector::resize(size_type, const value_type&)): Likewise. * testsuite/testsuite_hooks.h: Add NonDefaultConstructible test type. * testsuite/23_containers/deque/explicit_instantiation/2.cc: New. * testsuite/23_containers/list/explicit_instantiation/2.cc: New. * testsuite/23_containers/map/explicit_instantiation/2.cc: New. * testsuite/23_containers/multimap/explicit_instantiation/2.cc: New. * testsuite/23_containers/multiset/explicit_instantiation/2.cc: New. * testsuite/23_containers/set/explicit_instantiation/2.cc: New. * testsuite/23_containers/vector/explicit_instantiation/2.cc: New. * include/bits/deque.tcc: Minor formatting fix. From-SVN: r100668 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 442fb3f6b6c8..3a91b0019e0d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,35 @@ +2005-06-06 Paolo Carlini + + Port from libstdcxx_so_7-branch: + 2004-09-24 Paolo Carlini + Jonathan Wakely + + * include/bits/stl_list.h (list::list(size_type, value_type, + const allocator_type&): Implement according to the letter of the + standard, i.e., don't use two overloads, not equivalent in case + of non default constructible T. + (list::resize(size_type, const value_type&)): Fix the signature: + according to the standard the second argument is by value; also, + don't use two overloads. + * include/bits/list.tcc (list::resize(size_type, const value_type&)): + Adjust consistently the signature. + * include/bits/stl_deque.h (deque::deque(size_type, value_type, + const allocator_type&)): Likewise. + (deque::resize(size_type, const value_type&)): Likewise. + * include/bits/stl_vector.h (vector::vector(size_type, value_type, + const allocator_type&)): Likewise. + (vector::resize(size_type, const value_type&)): Likewise. + * testsuite/testsuite_hooks.h: Add NonDefaultConstructible test type. + * testsuite/23_containers/deque/explicit_instantiation/2.cc: New. + * testsuite/23_containers/list/explicit_instantiation/2.cc: New. + * testsuite/23_containers/map/explicit_instantiation/2.cc: New. + * testsuite/23_containers/multimap/explicit_instantiation/2.cc: New. + * testsuite/23_containers/multiset/explicit_instantiation/2.cc: New. + * testsuite/23_containers/set/explicit_instantiation/2.cc: New. + * testsuite/23_containers/vector/explicit_instantiation/2.cc: New. + + * include/bits/deque.tcc: Minor formatting fix. + 2005-06-06 Peter Doerfler * include/bits/stl_function.h: ... and another one. diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index 35ceb69b402f..e69c79a4f34a 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -201,9 +201,9 @@ namespace _GLIBCXX_STD template template void - deque<_Tp, _Alloc> - ::_M_assign_aux(_InputIterator __first, _InputIterator __last, - std::input_iterator_tag) + deque<_Tp, _Alloc>:: + _M_assign_aux(_InputIterator __first, _InputIterator __last, + std::input_iterator_tag) { iterator __cur = begin(); for (; __first != __last && __cur != end(); ++__cur, ++__first) diff --git a/libstdc++-v3/include/bits/list.tcc b/libstdc++-v3/include/bits/list.tcc index 14ea0f0dbfac..d65f73c0beec 100644 --- a/libstdc++-v3/include/bits/list.tcc +++ b/libstdc++-v3/include/bits/list.tcc @@ -1,6 +1,6 @@ // List implementation (out of line) -*- C++ -*- -// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. +// Copyright (C) 2001, 2002, 2003, 2004, 2005 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 @@ -102,7 +102,7 @@ namespace _GLIBCXX_STD template void list<_Tp, _Alloc>:: - resize(size_type __new_size, const value_type& __x) + resize(size_type __new_size, value_type __x) { iterator __i = begin(); size_type __len = 0; diff --git a/libstdc++-v3/include/bits/stl_deque.h b/libstdc++-v3/include/bits/stl_deque.h index 249c4f2e7ee8..5a20b657a5fb 100644 --- a/libstdc++-v3/include/bits/stl_deque.h +++ b/libstdc++-v3/include/bits/stl_deque.h @@ -669,23 +669,12 @@ namespace _GLIBCXX_STD * * This constructor fills the %deque with @a n copies of @a value. */ - deque(size_type __n, const value_type& __value, + explicit + deque(size_type __n, const value_type& __value = value_type(), const allocator_type& __a = allocator_type()) : _Base(__a, __n) { _M_fill_initialize(__value); } - /** - * @brief Create a %deque with default elements. - * @param n The number of elements to initially create. - * - * This constructor fills the %deque with @a n copies of a - * default-constructed element. - */ - explicit - deque(size_type __n) - : _Base(allocator_type(), __n) - { _M_fill_initialize(value_type()); } - /** * @brief %Deque copy constructor. * @param x A %deque of identical element and allocator types. @@ -874,7 +863,7 @@ namespace _GLIBCXX_STD * data. */ void - resize(size_type __new_size, const value_type& __x) + resize(size_type __new_size, value_type __x = value_type()) { const size_type __len = size(); if (__new_size < __len) @@ -883,19 +872,6 @@ namespace _GLIBCXX_STD insert(this->_M_impl._M_finish, __new_size - __len, __x); } - /** - * @brief Resizes the %deque to the specified number of elements. - * @param new_size Number of elements the %deque should contain. - * - * This function will resize the %deque to the specified number - * of elements. If the number is smaller than the %deque's - * current size the %deque is truncated, otherwise the %deque - * is extended and new elements are default-constructed. - */ - void - resize(size_type new_size) - { resize(new_size, value_type()); } - /** * Returns true if the %deque is empty. (Thus begin() would * equal end().) diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index 879048063d1e..e17ec2b46068 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -472,23 +472,12 @@ namespace _GLIBCXX_STD * * This constructor fills the %list with @a n copies of @a value. */ - list(size_type __n, const value_type& __value, + explicit + list(size_type __n, const value_type& __value = value_type(), const allocator_type& __a = allocator_type()) : _Base(__a) { this->insert(begin(), __n, __value); } - /** - * @brief Create a %list with default elements. - * @param n The number of elements to initially create. - * - * This constructor fills the %list with @a n copies of a - * default-constructed element. - */ - explicit - list(size_type __n) - : _Base(allocator_type()) - { this->insert(begin(), __n, value_type()); } - /** * @brief %List copy constructor. * @param x A %list of identical element and allocator types. @@ -679,20 +668,7 @@ namespace _GLIBCXX_STD * extended and new elements are populated with given data. */ void - resize(size_type __new_size, const value_type& __x); - - /** - * @brief Resizes the %list to the specified number of elements. - * @param new_size Number of elements the %list should contain. - * - * This function will resize the %list to the specified number of - * elements. If the number is smaller than the %list's current - * size the %list is truncated, otherwise the %list is extended - * and new elements are default-constructed. - */ - void - resize(size_type __new_size) - { this->resize(__new_size, value_type()); } + resize(size_type __new_size, value_type __x = value_type()); // element access /** diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index dccc9dd96234..06b94017c010 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -206,7 +206,8 @@ namespace _GLIBCXX_STD * * This constructor fills the %vector with @a n copies of @a value. */ - vector(size_type __n, const value_type& __value, + explicit + vector(size_type __n, const value_type& __value = value_type(), const allocator_type& __a = allocator_type()) : _Base(__n, __a) { @@ -215,22 +216,6 @@ namespace _GLIBCXX_STD this->_M_impl._M_finish = this->_M_impl._M_start + __n; } - /** - * @brief Create a %vector with default elements. - * @param n The number of elements to initially create. - * - * This constructor fills the %vector with @a n copies of a - * default-constructed element. - */ - explicit - vector(size_type __n) - : _Base(__n, allocator_type()) - { - std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, value_type(), - _M_get_Tp_allocator()); - this->_M_impl._M_finish = this->_M_impl._M_start + __n; - } - /** * @brief %Vector copy constructor. * @param x A %vector of identical element and allocator types. @@ -429,7 +414,7 @@ namespace _GLIBCXX_STD * given data. */ void - resize(size_type __new_size, const value_type& __x) + resize(size_type __new_size, value_type __x = value_type()) { if (__new_size < size()) erase(begin() + __new_size, end()); @@ -437,20 +422,6 @@ namespace _GLIBCXX_STD insert(end(), __new_size - size(), __x); } - /** - * @brief Resizes the %vector to the specified number of elements. - * @param new_size Number of elements the %vector should contain. - * - * This function will resize the %vector to the specified - * number of elements. If the number is smaller than the - * %vector's current size the %vector is truncated, otherwise - * the %vector is extended and new elements are - * default-constructed. - */ - void - resize(size_type __new_size) - { resize(__new_size, value_type()); } - /** * Returns the total number of elements that the %vector can * hold before needing to allocate more memory. diff --git a/libstdc++-v3/testsuite/23_containers/deque/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/deque/explicit_instantiation/2.cc new file mode 100644 index 000000000000..7084ff746a0e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/explicit_instantiation/2.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// This file tests explicit instantiation of library containers + +#include +#include + +// { dg-do compile } + +template class std::deque<__gnu_test::NonDefaultConstructible>; diff --git a/libstdc++-v3/testsuite/23_containers/list/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/list/explicit_instantiation/2.cc new file mode 100644 index 000000000000..66d3934f4275 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/explicit_instantiation/2.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// This file tests explicit instantiation of library containers + +#include +#include + +// { dg-do compile } + +template class std::list<__gnu_test::NonDefaultConstructible>; diff --git a/libstdc++-v3/testsuite/23_containers/map/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/map/explicit_instantiation/2.cc new file mode 100644 index 000000000000..8c3c744f0809 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/explicit_instantiation/2.cc @@ -0,0 +1,37 @@ +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// This file tests explicit instantiation of library containers + +#include +#include + +// { dg-do compile } + +// N.B. We cannot instantiate with T == NonDefaultConstructible +// because of 23.3.1.2. +template class std::map<__gnu_test::NonDefaultConstructible, double>; diff --git a/libstdc++-v3/testsuite/23_containers/multimap/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/multimap/explicit_instantiation/2.cc new file mode 100644 index 000000000000..46181ef3e25b --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multimap/explicit_instantiation/2.cc @@ -0,0 +1,36 @@ +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// This file tests explicit instantiation of library containers + +#include +#include + +// { dg-do compile } + +template class std::multimap<__gnu_test::NonDefaultConstructible, + __gnu_test::NonDefaultConstructible>; diff --git a/libstdc++-v3/testsuite/23_containers/multiset/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/multiset/explicit_instantiation/2.cc new file mode 100644 index 000000000000..0f5f3080aa4e --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/explicit_instantiation/2.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// This file tests explicit instantiation of library containers + +#include +#include + +// { dg-do compile } + +template class std::multiset<__gnu_test::NonDefaultConstructible>; diff --git a/libstdc++-v3/testsuite/23_containers/set/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/set/explicit_instantiation/2.cc new file mode 100644 index 000000000000..418c80e55434 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/explicit_instantiation/2.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// This file tests explicit instantiation of library containers + +#include +#include + +// { dg-do compile } + +template class std::set<__gnu_test::NonDefaultConstructible>; diff --git a/libstdc++-v3/testsuite/23_containers/vector/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/23_containers/vector/explicit_instantiation/2.cc new file mode 100644 index 000000000000..7020d42ebb01 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/explicit_instantiation/2.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2004 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// This file tests explicit instantiation of library containers + +#include +#include + +// { dg-do compile } + +template class std::vector<__gnu_test::NonDefaultConstructible>; diff --git a/libstdc++-v3/testsuite/testsuite_hooks.h b/libstdc++-v3/testsuite/testsuite_hooks.h index 90104d36523b..fc05186d400d 100644 --- a/libstdc++-v3/testsuite/testsuite_hooks.h +++ b/libstdc++-v3/testsuite/testsuite_hooks.h @@ -160,6 +160,24 @@ namespace __gnu_test void run_tests_wrapped_env(const char*, const char*, const func_callback&); + + // For containers (23.1/3). + struct NonDefaultConstructible + { + NonDefaultConstructible(int) { } + }; + + inline bool + operator==(const NonDefaultConstructible& lhs, + const NonDefaultConstructible& rhs) + { return false; } + + inline bool + operator<(const NonDefaultConstructible& lhs, + const NonDefaultConstructible& rhs) + { return false; } + + // Counting. struct counter {