This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch] Fix libstdc++/16500


Hi,

this is a conservative fix for the PR, in that it doesn't touch the
__uninitialized_fill_n_aux helpers. In case someone believes it would
be appropriate changing right away also the latters to return void,
just let me know, otherwise I will commit it as-is later today.

Tested x86-linux.

Paolo.

/////////////////////
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.
diff -urN libstdc++-v3-orig/include/bits/stl_uninitialized.h libstdc++-v3/include/bits/stl_uninitialized.h
--- libstdc++-v3-orig/include/bits/stl_uninitialized.h	2004-02-08 05:46:42.000000000 +0100
+++ libstdc++-v3/include/bits/stl_uninitialized.h	2004-07-14 10:23:11.000000000 +0200
@@ -82,7 +82,7 @@
       _ForwardIterator __cur = __result;
       try
 	{
-	  for ( ; __first != __last; ++__first, ++__cur)
+	  for (; __first != __last; ++__first, ++__cur)
 	    std::_Construct(&*__cur, *__first);
 	  return __cur;
 	}
@@ -145,7 +145,7 @@
       _ForwardIterator __cur = __first;
       try
 	{
-	  for ( ; __cur != __last; ++__cur)
+	  for (; __cur != __last; ++__cur)
 	    std::_Construct(&*__cur, __x);
 	}
       catch(...)
@@ -190,7 +190,7 @@
       _ForwardIterator __cur = __first;
       try
 	{
-	  for ( ; __n > 0; --__n, ++__cur)
+	  for (; __n > 0; --__n, ++__cur)
 	    std::_Construct(&*__cur, __x);
 	  return __cur;
 	}
@@ -206,17 +206,17 @@
    *  @param  first  An input iterator.
    *  @param  n      The number of copies to make.
    *  @param  x      The source value.
-   *  @return   first+n
+   *  @return   Nothing.
    *
    *  Like fill_n(), but does not require an initialized output range.
   */
   template<typename _ForwardIterator, typename _Size, typename _Tp>
-    inline _ForwardIterator
+    inline void
     uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
     {
       typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
       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,
diff -urN libstdc++-v3-orig/include/bits/stl_vector.h libstdc++-v3/include/bits/stl_vector.h
--- libstdc++-v3-orig/include/bits/stl_vector.h	2004-07-12 15:23:58.000000000 +0200
+++ libstdc++-v3/include/bits/stl_vector.h	2004-07-14 10:46:57.000000000 +0200
@@ -118,7 +118,8 @@
 
       void
       _M_deallocate(_Tp* __p, size_t __n)
-      { if (__p)
+      {
+	if (__p)
 	  _M_impl.deallocate(__p, __n);
       }
     };
@@ -198,9 +199,10 @@
       vector(size_type __n, const value_type& __value,
 	     const allocator_type& __a = allocator_type())
       : _Base(__n, __a)
-      { this->_M_impl._M_finish = std::uninitialized_fill_n(this->
-							    _M_impl._M_start,
-							    __n, __value); }
+      {
+	std::uninitialized_fill_n(this->_M_impl._M_start, __n, __value);
+	this->_M_impl._M_finish = this->_M_impl._M_start + __n;
+      }
 
       /**
        *  @brief  Create a %vector with default elements.
@@ -212,10 +214,10 @@
       explicit
       vector(size_type __n)
       : _Base(__n, allocator_type())
-      { this->_M_impl._M_finish = std::uninitialized_fill_n(this->
-							    _M_impl._M_start,
-							    __n,
-							    value_type()); }
+      {
+	std::uninitialized_fill_n(this->_M_impl._M_start, __n, value_type());
+	this->_M_impl._M_finish = this->_M_impl._M_start + __n;	
+      }
 
       /**
        *  @brief  %Vector copy constructor.
@@ -231,8 +233,7 @@
       { this->_M_impl._M_finish = std::uninitialized_copy(__x.begin(),
 							  __x.end(),
 							  this->
-							  _M_impl._M_start);
-      }
+							  _M_impl._M_start); }
 
       /**
        *  @brief  Builds a %vector from a range.
@@ -777,9 +778,8 @@
         {
 	  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_finish = std::uninitialized_fill_n(this->
-							      _M_impl._M_start,
-							      __n, __value);
+	  std::uninitialized_fill_n(this->_M_impl._M_start, __n, __value);
+	  this->_M_impl._M_finish = this->_M_impl._M_end_of_storage;
 	}
 
       // Called by the range constructor to implement [23.1.1]/9
diff -urN libstdc++-v3-orig/include/bits/vector.tcc libstdc++-v3/include/bits/vector.tcc
--- libstdc++-v3-orig/include/bits/vector.tcc	2004-07-12 15:23:58.000000000 +0200
+++ libstdc++-v3/include/bits/vector.tcc	2004-07-14 10:48:34.000000000 +0200
@@ -176,10 +176,9 @@
       else if (__n > size())
 	{
 	  std::fill(begin(), end(), __val);
-	  this->_M_impl._M_finish = std::uninitialized_fill_n(this->
-							      _M_impl._M_finish,
-							      __n - size(),
-							      __val);
+	  std::uninitialized_fill_n(this->_M_impl._M_finish,
+				    __n - size(), __val);
+	  this->_M_impl._M_finish += __n - size();
 	}
       else
         erase(fill_n(begin(), __n, __val), end());
@@ -336,15 +335,15 @@
 		{
 		  __new_finish = std::uninitialized_copy(begin(), __position,
 							 __new_start);
-		  __new_finish = std::uninitialized_fill_n(__new_finish, __n,
-							   __x);
+		  std::uninitialized_fill_n(__new_finish, __n, __x);
+		  __new_finish += __n;
 		  __new_finish = std::uninitialized_copy(__position, end(),
 							 __new_finish);
 		}
 	      catch(...)
 		{
-		  std::_Destroy(__new_start,__new_finish);
-		  _M_deallocate(__new_start.base(),__len);
+		  std::_Destroy(__new_start, __new_finish);
+		  _M_deallocate(__new_start.base(), __len);
 		  __throw_exception_again;
 		}
 	      std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish);
diff -urN libstdc++-v3-orig/testsuite/20_util/memory/16505.cc libstdc++-v3/testsuite/20_util/memory/16505.cc
--- libstdc++-v3-orig/testsuite/20_util/memory/16505.cc	1970-01-01 01:00:00.000000000 +0100
+++ libstdc++-v3/testsuite/20_util/memory/16505.cc	2004-07-14 11:18:30.000000000 +0200
@@ -0,0 +1,31 @@
+// 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&);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]