You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by Anton Pevtsov <An...@moscow.vdiweb.com> on 2006/05/17 15:11:24 UTC

RE: svn commit: r407120 - /incubator/stdcxx/trunk/include/vector.cc

Martin, after applying your changes I got the following warning on
Linux, gcc 4.0.2:

stdcxx/trunk/include/vector.cc: In member function 'void
std::vector<_TypeT, _Allocator>::_C_insert_range(typename
_Allocator::pointer, _FwdIter, _FwdIter, std::forward_iterator_tag)':
stdcxx/trunk/include/vector.cc:630: warning: declaration of '__end'
shadows a previous local
stdcxx/trunk/include/vector.cc:601: warning: shadowed declaration is
here

Is this correct? 


Thanks,
Anton Pevtsov

-----Original Message-----
From: sebor@apache.org [mailto:sebor@apache.org] 
Sent: Wednesday, May 17, 2006 05:29
To: stdcxx-commits@incubator.apache.org
Subject: svn commit: r407120 - /incubator/stdcxx/trunk/include/vector.cc


Author: sebor
Date: Tue May 16 18:28:38 2006
New Revision: 407120

URL: http://svn.apache.org/viewcvs?rev=407120&view=rev
Log:
2006-05-16  Martin Sebor  <se...@roguewave.com>

	STDCXX-179
	* vector.cc (_C_insert_range): Corrected the persistent logic
	error in the computation of the end of the range of elements
	to be overwritten (assigned).

Modified:
    incubator/stdcxx/trunk/include/vector.cc

Modified: incubator/stdcxx/trunk/include/vector.cc
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/include/vector.cc?r
ev=407120&r1=407119&r2=407120&view=diff
========================================================================
======
--- incubator/stdcxx/trunk/include/vector.cc (original)
+++ incubator/stdcxx/trunk/include/vector.cc Tue May 16 18:28:38 2006
@@ -589,38 +589,35 @@
 
     if (__insert_in_place) {
 
-        // compute the beginning of the range of elements in the
sequence
-        // controlled by *this that need to be moved (copy contructed
past
-        // the end of the end of the sequence or assigned over existing
-        // elements)
+        // compute the beginning an end of the range of elements
+        // in the sequence controlled by *this that need to be moved
+        // (copy contructed past the end of the end of the sequence
+        // or assigned over existing elements)
         const pointer __movbeg = __self->_C_begin + __size1;
+        const pointer __movend = __movbeg + __size2;
+
         _RWSTD_ASSERT (__self->_C_make_iter (__movbeg) == __it);
 
-        if (__movbeg + __size2 <= __self->_C_end) {
+        const pointer __end = __self->_C_end;
+
+        if (__movend <= __end) {
 
             // compute the beginning of the range of elements whose
copies
-            // will be constructed just past the current end of the
sequence
-            pointer __ucpbeg = __self->_C_end - __size2;
+            // will be copy-constructed in the uninitialized space just
past
+            // the current end of the sequence
+            const pointer __ucpbeg = __end - __size2;
 
             // construct copies of elements that will be moved beyond
-            // the current end of the sequence controlled by *this as
-            // if by calling
-            // std::uninitialized_copy (__ucpbeg, _C_end, _C_end);
-            pointer __end = __self->_C_end;
-
+            // the current end of the sequence controlled by *this
             pointer __p;
 
             for (__p = __ucpbeg; !(__p == __end); ++__p,
++__self->_C_end)
                 __self->_C_construct (__self->_C_end, *__p);
 
             // copy elements that will be overwritten below
-            // over the range of elements moved above as if
-            // by a call to
-            // std::copy_backward (__movbeg, __ucpbeg, __movbeg);
-
-            for (__p = __ucpbeg; !(__p == __movbeg); ) {
-                *__ucpbeg-- = *--__p;
-            }
+            // over the range of elements moved above
+            for (__p = __end; __movend < __p--; )
+                *__p = *(__p - __size2);
         }
         else {
             // compute the length of the initial subsequence of the
range



Re: svn commit: r407120 - /incubator/stdcxx/trunk/include/vector.cc

Posted by Martin Sebor <se...@roguewave.com>.
Anton Pevtsov wrote:
> Martin, after applying your changes I got the following warning on
> Linux, gcc 4.0.2:
> 
> stdcxx/trunk/include/vector.cc: In member function 'void
> std::vector<_TypeT, _Allocator>::_C_insert_range(typename
> _Allocator::pointer, _FwdIter, _FwdIter, std::forward_iterator_tag)':
> stdcxx/trunk/include/vector.cc:630: warning: declaration of '__end'
> shadows a previous local
> stdcxx/trunk/include/vector.cc:601: warning: shadowed declaration is
> here
> 
> Is this correct? 

It shouldn't cause any misbehavior but we certainly want
warning-free builds. I tested with Intel C++ which doesn't
issue the warning and the copy I tested with gcc has some
other changes that removed the source of the warning.
Thanks for pointing it out! I'll fix it today.

Martin

> 
> 
> Thanks,
> Anton Pevtsov
> 
> -----Original Message-----
> From: sebor@apache.org [mailto:sebor@apache.org] 
> Sent: Wednesday, May 17, 2006 05:29
> To: stdcxx-commits@incubator.apache.org
> Subject: svn commit: r407120 - /incubator/stdcxx/trunk/include/vector.cc
> 
> 
> Author: sebor
> Date: Tue May 16 18:28:38 2006
> New Revision: 407120
> 
> URL: http://svn.apache.org/viewcvs?rev=407120&view=rev
> Log:
> 2006-05-16  Martin Sebor  <se...@roguewave.com>
> 
> 	STDCXX-179
> 	* vector.cc (_C_insert_range): Corrected the persistent logic
> 	error in the computation of the end of the range of elements
> 	to be overwritten (assigned).
> 
> Modified:
>     incubator/stdcxx/trunk/include/vector.cc
> 
> Modified: incubator/stdcxx/trunk/include/vector.cc
> URL:
> http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/include/vector.cc?r
> ev=407120&r1=407119&r2=407120&view=diff
> ========================================================================
> ======
> --- incubator/stdcxx/trunk/include/vector.cc (original)
> +++ incubator/stdcxx/trunk/include/vector.cc Tue May 16 18:28:38 2006
> @@ -589,38 +589,35 @@
>  
>      if (__insert_in_place) {
>  
> -        // compute the beginning of the range of elements in the
> sequence
> -        // controlled by *this that need to be moved (copy contructed
> past
> -        // the end of the end of the sequence or assigned over existing
> -        // elements)
> +        // compute the beginning an end of the range of elements
> +        // in the sequence controlled by *this that need to be moved
> +        // (copy contructed past the end of the end of the sequence
> +        // or assigned over existing elements)
>          const pointer __movbeg = __self->_C_begin + __size1;
> +        const pointer __movend = __movbeg + __size2;
> +
>          _RWSTD_ASSERT (__self->_C_make_iter (__movbeg) == __it);
>  
> -        if (__movbeg + __size2 <= __self->_C_end) {
> +        const pointer __end = __self->_C_end;
> +
> +        if (__movend <= __end) {
>  
>              // compute the beginning of the range of elements whose
> copies
> -            // will be constructed just past the current end of the
> sequence
> -            pointer __ucpbeg = __self->_C_end - __size2;
> +            // will be copy-constructed in the uninitialized space just
> past
> +            // the current end of the sequence
> +            const pointer __ucpbeg = __end - __size2;
>  
>              // construct copies of elements that will be moved beyond
> -            // the current end of the sequence controlled by *this as
> -            // if by calling
> -            // std::uninitialized_copy (__ucpbeg, _C_end, _C_end);
> -            pointer __end = __self->_C_end;
> -
> +            // the current end of the sequence controlled by *this
>              pointer __p;
>  
>              for (__p = __ucpbeg; !(__p == __end); ++__p,
> ++__self->_C_end)
>                  __self->_C_construct (__self->_C_end, *__p);
>  
>              // copy elements that will be overwritten below
> -            // over the range of elements moved above as if
> -            // by a call to
> -            // std::copy_backward (__movbeg, __ucpbeg, __movbeg);
> -
> -            for (__p = __ucpbeg; !(__p == __movbeg); ) {
> -                *__ucpbeg-- = *--__p;
> -            }
> +            // over the range of elements moved above
> +            for (__p = __end; __movend < __p--; )
> +                *__p = *(__p - __size2);
>          }
>          else {
>              // compute the length of the initial subsequence of the
> range
>