This is the mail archive of the gcc-help@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]

Re: confusion about string.erase( --string.end() )


On Tue, 22 Nov 2011, Pawel Sikora wrote:

Hi,

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++?

Hello,


your code is wrong. Libraries that use pointers as iterators will fail. Libraries that use classes are likely to work. There is nothing wrong with the fact that libstdc++ accepts this code.

When references on member functions are implemented, it would be possible to reject this code, but I am not sure we want to.

--
Marc Glisse


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