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]

libstdc++/6642: Constness prevents substraction of iterators



>Number:         6642
>Category:       libstdc++
>Synopsis:       Constness prevents substraction of iterators
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sun May 12 22:26:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Oscar Fuentes
>Release:        gcc version 3.1 20020510 (prerelease)
>Organization:
>Environment:
Reading specs from t:\msys\1.0\mingw\bin\..\lib\gcc-lib\i686-pc-mingw32\3.1\specs
Configured with: ../gcc-3.1-20020510/configure --enable-languages=c,c++ --enable-threads=win32 --enable-sjlj-exceptions --prefix=t:/msys/1.0/mingw
Thread model: win32
gcc version 3.1 20020510 (prerelease)
>Description:
Substraction of iterators being the first operand 'non-const' and the second 'const' are not possible.
>How-To-Repeat:
#include <string>

class MyClass {
private:
  std::string s;
  std::string::iterator it;
public:
  unsigned pos() const {
    return it - s.begin();
  }
};

Gives

t:/msys/1.0/mingw/include/g++-v3/bits/stl_iterator.h: In constructor 
   `__gnu_cxx::__normal_iterator<_Iterator, 
   _Container>::__normal_iterator(const __gnu_cxx::__normal_iterator<_Iter, 
   _Container>&) [with _Iter = const char*, _Iterator = char*, _Container = 
   std::basic_string<char, std::char_traits<char>, std::allocator<char> >]':
case.cpp:9:   instantiated from here
t:/msys/1.0/mingw/include/g++-v3/bits/stl_iterator.h:589: invalid conversion 
   from `const char* const' to `char*'

>Fix:
-(s.begin() - it) works :-)
>Release-Note:
>Audit-Trail:
>Unformatted:


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