Commit 368b7a30 by Paolo Carlini Committed by Paolo Carlini

re PR libstdc++/16505 ([3.4 only] std::uninitialized_fill_n() incorrect signature)

2004-07-14  Paolo Carlini  <pcarlini@suse.de>

	PR libstdc++/16505
	* include/bits/stl_uninitialized.h (uninitialized_fill_n): Fix
	the signature to return void, as per 20.4.4.3.
	* include/bits/stl_vector.h (vector::vector(size_type,
	const value_type&, const allocator_type&), vector::vector(size_type),
	vector::_M_initialize_dispatch): Adjust callers.
	* include/bits/vector.tcc (vector<>::_M_fill_assign,
	vector<>::_M_fill_insert): Likewise.
	* testsuite/20_util/memory/16505.cc: New.

From-SVN: r84720
parent 7ae4ad28
2004-07-14 Paolo Carlini <pcarlini@suse.de> 2004-07-14 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/16505
* include/bits/stl_uninitialized.h (uninitialized_fill_n): Fix
the signature to return void, as per 20.4.4.3.
* include/bits/stl_vector.h (vector::vector(size_type,
const value_type&, const allocator_type&), vector::vector(size_type),
vector::_M_initialize_dispatch): Adjust callers.
* include/bits/vector.tcc (vector<>::_M_fill_assign,
vector<>::_M_fill_insert): Likewise.
* testsuite/20_util/memory/16505.cc: New.
2004-07-14 Paolo Carlini <pcarlini@suse.de>
* testsuite/22_locale/locale/cons/12658_thread-1.cc, * testsuite/22_locale/locale/cons/12658_thread-1.cc,
12658_thread-2.cc: Use __gnu_test::try_named_locale. 12658_thread-2.cc: Use __gnu_test::try_named_locale.
......
...@@ -82,7 +82,7 @@ namespace std ...@@ -82,7 +82,7 @@ namespace std
_ForwardIterator __cur = __result; _ForwardIterator __cur = __result;
try try
{ {
for ( ; __first != __last; ++__first, ++__cur) for (; __first != __last; ++__first, ++__cur)
std::_Construct(&*__cur, *__first); std::_Construct(&*__cur, *__first);
return __cur; return __cur;
} }
...@@ -145,7 +145,7 @@ namespace std ...@@ -145,7 +145,7 @@ namespace std
_ForwardIterator __cur = __first; _ForwardIterator __cur = __first;
try try
{ {
for ( ; __cur != __last; ++__cur) for (; __cur != __last; ++__cur)
std::_Construct(&*__cur, __x); std::_Construct(&*__cur, __x);
} }
catch(...) catch(...)
...@@ -190,7 +190,7 @@ namespace std ...@@ -190,7 +190,7 @@ namespace std
_ForwardIterator __cur = __first; _ForwardIterator __cur = __first;
try try
{ {
for ( ; __n > 0; --__n, ++__cur) for (; __n > 0; --__n, ++__cur)
std::_Construct(&*__cur, __x); std::_Construct(&*__cur, __x);
return __cur; return __cur;
} }
...@@ -206,17 +206,17 @@ namespace std ...@@ -206,17 +206,17 @@ namespace std
* @param first An input iterator. * @param first An input iterator.
* @param n The number of copies to make. * @param n The number of copies to make.
* @param x The source value. * @param x The source value.
* @return first+n * @return Nothing.
* *
* Like fill_n(), but does not require an initialized output range. * Like fill_n(), but does not require an initialized output range.
*/ */
template<typename _ForwardIterator, typename _Size, typename _Tp> template<typename _ForwardIterator, typename _Size, typename _Tp>
inline _ForwardIterator inline void
uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x) uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
{ {
typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD; typedef typename __type_traits<_ValueType>::is_POD_type _Is_POD;
return std::__uninitialized_fill_n_aux(__first, __n, __x, _Is_POD()); std::__uninitialized_fill_n_aux(__first, __n, __x, _Is_POD());
} }
// Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill, // Extensions: __uninitialized_copy_copy, __uninitialized_copy_fill,
......
...@@ -118,7 +118,8 @@ namespace _GLIBCXX_STD ...@@ -118,7 +118,8 @@ namespace _GLIBCXX_STD
void void
_M_deallocate(_Tp* __p, size_t __n) _M_deallocate(_Tp* __p, size_t __n)
{ if (__p) {
if (__p)
_M_impl.deallocate(__p, __n); _M_impl.deallocate(__p, __n);
} }
}; };
...@@ -198,9 +199,10 @@ namespace _GLIBCXX_STD ...@@ -198,9 +199,10 @@ namespace _GLIBCXX_STD
vector(size_type __n, const value_type& __value, vector(size_type __n, const value_type& __value,
const allocator_type& __a = allocator_type()) const allocator_type& __a = allocator_type())
: _Base(__n, __a) : _Base(__n, __a)
{ this->_M_impl._M_finish = std::uninitialized_fill_n(this-> {
_M_impl._M_start, std::uninitialized_fill_n(this->_M_impl._M_start, __n, __value);
__n, __value); } this->_M_impl._M_finish = this->_M_impl._M_start + __n;
}
/** /**
* @brief Create a %vector with default elements. * @brief Create a %vector with default elements.
...@@ -212,10 +214,10 @@ namespace _GLIBCXX_STD ...@@ -212,10 +214,10 @@ namespace _GLIBCXX_STD
explicit explicit
vector(size_type __n) vector(size_type __n)
: _Base(__n, allocator_type()) : _Base(__n, allocator_type())
{ this->_M_impl._M_finish = std::uninitialized_fill_n(this-> {
_M_impl._M_start, std::uninitialized_fill_n(this->_M_impl._M_start, __n, value_type());
__n, this->_M_impl._M_finish = this->_M_impl._M_start + __n;
value_type()); } }
/** /**
* @brief %Vector copy constructor. * @brief %Vector copy constructor.
...@@ -231,8 +233,7 @@ namespace _GLIBCXX_STD ...@@ -231,8 +233,7 @@ namespace _GLIBCXX_STD
{ this->_M_impl._M_finish = std::uninitialized_copy(__x.begin(), { this->_M_impl._M_finish = std::uninitialized_copy(__x.begin(),
__x.end(), __x.end(),
this-> this->
_M_impl._M_start); _M_impl._M_start); }
}
/** /**
* @brief Builds a %vector from a range. * @brief Builds a %vector from a range.
...@@ -777,9 +778,8 @@ namespace _GLIBCXX_STD ...@@ -777,9 +778,8 @@ namespace _GLIBCXX_STD
{ {
this->_M_impl._M_start = _M_allocate(__n); this->_M_impl._M_start = _M_allocate(__n);
this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
this->_M_impl._M_finish = std::uninitialized_fill_n(this-> std::uninitialized_fill_n(this->_M_impl._M_start, __n, __value);
_M_impl._M_start, this->_M_impl._M_finish = this->_M_impl._M_end_of_storage;
__n, __value);
} }
// Called by the range constructor to implement [23.1.1]/9 // Called by the range constructor to implement [23.1.1]/9
......
...@@ -176,10 +176,9 @@ namespace _GLIBCXX_STD ...@@ -176,10 +176,9 @@ namespace _GLIBCXX_STD
else if (__n > size()) else if (__n > size())
{ {
std::fill(begin(), end(), __val); std::fill(begin(), end(), __val);
this->_M_impl._M_finish = std::uninitialized_fill_n(this-> std::uninitialized_fill_n(this->_M_impl._M_finish,
_M_impl._M_finish, __n - size(), __val);
__n - size(), this->_M_impl._M_finish += __n - size();
__val);
} }
else else
erase(fill_n(begin(), __n, __val), end()); erase(fill_n(begin(), __n, __val), end());
...@@ -336,15 +335,15 @@ namespace _GLIBCXX_STD ...@@ -336,15 +335,15 @@ namespace _GLIBCXX_STD
{ {
__new_finish = std::uninitialized_copy(begin(), __position, __new_finish = std::uninitialized_copy(begin(), __position,
__new_start); __new_start);
__new_finish = std::uninitialized_fill_n(__new_finish, __n, std::uninitialized_fill_n(__new_finish, __n, __x);
__x); __new_finish += __n;
__new_finish = std::uninitialized_copy(__position, end(), __new_finish = std::uninitialized_copy(__position, end(),
__new_finish); __new_finish);
} }
catch(...) catch(...)
{ {
std::_Destroy(__new_start,__new_finish); std::_Destroy(__new_start, __new_finish);
_M_deallocate(__new_start.base(),__len); _M_deallocate(__new_start.base(), __len);
__throw_exception_again; __throw_exception_again;
} }
std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish);
......
// 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.
// 20.4.4 specialized algorithms
// { dg-do compile }
#include <memory>
// libstdc++/16505
struct S { };
template
void
std::uninitialized_fill_n<S*, int, S>(S*, int, const S&);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment