From dev-return-7013-apmail-stdcxx-dev-archive=stdcxx.apache.org@stdcxx.apache.org Mon Mar 10 18:36:37 2008 Return-Path: Delivered-To: apmail-stdcxx-dev-archive@www.apache.org Received: (qmail 29469 invoked from network); 10 Mar 2008 18:36:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Mar 2008 18:36:37 -0000 Received: (qmail 35504 invoked by uid 500); 10 Mar 2008 18:36:34 -0000 Delivered-To: apmail-stdcxx-dev-archive@stdcxx.apache.org Received: (qmail 35494 invoked by uid 500); 10 Mar 2008 18:36:33 -0000 Mailing-List: contact dev-help@stdcxx.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@stdcxx.apache.org Delivered-To: mailing list dev@stdcxx.apache.org Received: (qmail 35479 invoked by uid 99); 10 Mar 2008 18:36:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Mar 2008 11:36:33 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [208.30.140.160] (HELO moroha.roguewave.com) (208.30.140.160) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Mar 2008 18:35:44 +0000 Received: from exchmail01.Blue.Roguewave.Com (exchmail01.blue.roguewave.com [10.22.129.22]) by moroha.roguewave.com (8.13.6/8.13.6) with ESMTP id m2AIa30Y024506 for ; Mon, 10 Mar 2008 18:36:03 GMT X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: svn commit: r635439 - /stdcxx/trunk/include/string.cc Date: Mon, 10 Mar 2008 12:35:53 -0600 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: svn commit: r635439 - /stdcxx/trunk/include/string.cc Thread-Index: AciCcx5DYB0tGFhxQD+KgZU4W9y+gQAXUdcg References: <20080310055240.54E151A9832@eris.apache.org> From: "Travis Vitek" To: X-Virus-Checked: Checked by ClamAV on apache.org =20 >Author: faridz >Date: Sun Mar 9 22:52:37 2008 >New Revision: 635439 > >URL: http://svn.apache.org/viewvc?rev=3D635439&view=3Drev >Log: >2008-03-10 Farid Zaripov > > * include/string.cc (__replace_aux): Use static_cast<>() > instead of reinterpret_cast<>() to prevent compile error > when _InputIter::operator*() returns rvalue. > >Modified: > stdcxx/trunk/include/string.cc > >Modified: stdcxx/trunk/include/string.cc >URL:=20 >http://svn.apache.org/viewvc/stdcxx/trunk/include/string.cc?rev =3D635439&r1=3D635438&r2=3D635439&view=3Ddiff >=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >--- stdcxx/trunk/include/string.cc (original) >+++ stdcxx/trunk/include/string.cc Sun Mar 9 22:52:37 2008 >@@ -652,7 +652,7 @@ >=20 > if (__n2) { > const const_pointer __ptr =3D >- &_RWSTD_REINTERPRET_CAST=20 >(const_reference, *__first2); >+ &_RWSTD_STATIC_CAST (const_reference, *__first2); >=20 > if (__s.data () <=3D __ptr && __s.data () +=20 >__ssize > __ptr) { > const _RWSTD_SIZE_T __tmp_size =3D __n2 *=20 >sizeof (value_type); > > > Farid, Is this actually safe, and does it actually do what you want? If _InputIter::operator* returns a rvalue and you static_cast that to a const_reference, you will get the address of the temporary. That address can't reliably be used to to test that `__first2' is inside `__s' or not, so the bug that you are trying to eliminate here will still exist for iterators of this type. Here is a complete testcase. template struct dumb_forward_iterator { dumb_forward_iterator (_TypeT* p) : ptr (p) { } // generated... //dumb_forward_iterator (const dumb_forward_iterator& other); // // generated... //dumb_forward_iterator& //operator=3D (const dumb_forward_iterator& other); _TypeT operator* () { return *ptr; } _TypeT operator* () const { return *ptr; } _TypeT* operator-> () { return ptr; } const _TypeT* operator-> () const { return ptr; } dumb_forward_iterator& operator++ () { ++ptr; return *this; } dumb_forward_iterator operator++ (int) { dumb_forward_iterator tmp (*this); ++ptr; return tmp; } _TypeT* ptr; }; template bool operator=3D=3D (const dumb_forward_iterator<_TypeT>& lhs, const dumb_forward_iterator<_TypeT>& rhs) { return lhs.ptr =3D=3D rhs.ptr; } template bool operator!=3D (const dumb_forward_iterator<_TypeT>& lhs, const dumb_forward_iterator<_TypeT>& rhs) { return lhs.ptr !=3D rhs.ptr; } #include #include template struct string { typedef _CharT value_type; typedef _CharT* iterator; typedef const _CharT* const_iterator; typedef _CharT& reference; typedef const _CharT& const_reference; typedef _CharT* pointer; typedef const _CharT* const_pointer; string (const _CharT* s) { int n =3D 0; while (s [n]) ++n; buf =3D (_CharT*)malloc (n + 1); size =3D n; for (int m =3D 0; m < n; ++m) buf [m] =3D s [m]; } ~string () { free (buf); } iterator begin () { return buf; } iterator end () { return buf + size; } _CharT* buf; int size; }; template void __replace_aux (string<_CharT>& __s, typename string<_CharT>::iterator __first1, typename string<_CharT>::iterator __last1, _InputIter __first2, _InputIter __last2) { const string<_CharT>::const_pointer __ptr =3D &static_cast::const_reference>(*__first2); if (__s.buf <=3D __ptr && __ptr < __s.buf + __s.size) printf ("__first2 is inside __s\n"); else printf ("__first2 is *not* inside __s\n"); } int main () { string s ("abc"); dumb_forward_iterator::value_type> dbeg (s.begin ()); dumb_forward_iterator::value_type> dend (s.end ()); __replace_aux (s, s.begin (), s.end (), dbeg, dend); return 0; } If _InputIter is a pointer type, you should not need a cast at all, and if it is a class type, you _should_ be able to use the result of operator->(), but that isn't really safe because it could return a proxy for the actual pointer. I think you could use SFINAE and traits to detect that the return type of operator->() is a pointer type if we really wanted to, and then just make a copy if it isn't. Travis