This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC 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]

[Bug libstdc++/11240] New: operator-() fails for reverse_iterator<const char*>


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11240

           Summary: operator-() fails for reverse_iterator<const char*>
           Product: gcc
           Version: 3.2.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ysbeer@af.org.za
                CC: gcc-bugs@gcc.gnu.org
 GCC build triplet: gcc version 3.2.2 20030222
  GCC host triplet: i386 (Linux/FreeBSD/Cygwin)

Finding differences between reverse_iterators of const char* are broken causing 
algorithms such as std::find to fail.  
 
The following code snippet produces the output 
 
  const char* FWD=3 
  const char* REV= 
  REV DIFF=-1208263166 
  string FWD=3 
  string REV=3 
 
instead of 
 
  const char* FWD=3 
  const char* REV= 3 
  REV DIFF=10 
  string FWD=3 
  string REV=3 
 
#include <iterator> 
#include <algorithm> 
#include <iostream> 
#include <string> 
#include <cstring> 
 
using namespace std; 
 
int main() 
{ 
	typedef reverse_iterator<const char*> REV; 
 
	const char s[]= "0123456789"; 
    const size_t size= strlen(s); 
	const string S(s); 
 
	const char* found= find( s,s+size,'3' ); 
	REV rfound= find(REV(s+size),REV(s),'3'); 
	cout << "const char* FWD=" << *found << endl; 
	cout << "const char* REV=" << *rfound << endl; 
	cout << "REV DIFF=" << (REV(s)-REV(s+size)) << endl; 
 
	string::const_iterator Found= find( S.begin(),S.end(),'3' ); 
	string::const_reverse_iterator rFound= find(S.rbegin(),S.rend(),'3'); 
	cout << "string FWD=" << *Found << endl; 
	cout << "string REV=" << *rFound << endl; 
 
	return 0; 
} 
 
Checked on (gcc -v): 
 
[1] Built with Configured with: ../configure --prefix=/usr --libdir=/usr/lib 
--with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared 
--enable-threads=posix --disable-checking --enable-long-long 
--enable-__cxa_atexit --enable-languages=c,c++,ada,f77,objc,java 
--host=i586-mandrake-linux-gnu --with-system-zlib 
Thread model: posix 
gcc version 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk) 
 
[2] gcc version 2.95.4 20020320 [FreeBSD] 
 
[3] gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81) 
 
[4] Configured with: ../configure --prefix=/usr --mandir=/usr/share/man 
--infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking 
--with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux 
Thread model: posix 
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5) 
 
[5] gcc version 3.2 20020927 (Cygwin) 
 
In all cases compiles done with simple "g++ filename.cpp" command. 
 
Sidenote: The problem disappears if 'const char s[]= "0123456789";' is changed to 
'char s[]="01234567890"'. This makes we wonder if there is  possibly an compiler 
optimisation issue involved.


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