This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: confusion about string.erase( --string.end() )
- From: Ian Lance Taylor <iant at google dot com>
- To: Pawel Sikora <pluto at agmk dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 22 Nov 2011 09:22:47 -0800
- Subject: Re: confusion about string.erase( --string.end() )
- References: <8433837.L6u1V86xfQ@pawels>
Pawel Sikora <pluto@agmk.net> writes:
> afaics the gcc-4.6 accepts following code:
>
> #include <string>
> int main()
> {
> std::string line( "blabla" );
> line.erase( --line.end() );
> }
>
> but other compilers reject such code:
>
> msvc8 : error C2105: '--' needs l-value
> comeau : error: expression must be a modifiable lvalue
>
> is it a bug in g++?
I don't think this is a bug. std::string::end is required to return a
std::string::iterator. The type of std::string::iterator is
implementation defined. It so happens that the g++ implementation of
std::string::iterator has an operator-- method. Apparently this is not
true of the implementations used by MSVC or Comeau. So it's not a bug,
it's just an implementation difference permitted by the standard.
Ian