From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9164 invoked by alias); 22 Nov 2011 17:06:04 -0000 Received: (qmail 9151 invoked by uid 22791); 22 Nov 2011 17:06:02 -0000 X-SWARE-Spam-Status: No, hits=-5.9 required=5.0 tests=AWL,BAYES_50,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail4-relais-sop.national.inria.fr (HELO mail4-relais-sop.national.inria.fr) (192.134.164.105) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Nov 2011 17:05:39 +0000 Received: from afontenayssb-151-1-16-164.w82-121.abo.wanadoo.fr (HELO laptop-mg.local) ([82.121.222.164]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 22 Nov 2011 18:05:37 +0100 Date: Tue, 22 Nov 2011 18:11:00 -0000 From: Marc Glisse Reply-To: gcc-help@gcc.gnu.org To: Pawel Sikora cc: gcc-help@gcc.gnu.org Subject: Re: confusion about string.erase( --string.end() ) In-Reply-To: <8433837.L6u1V86xfQ@pawels> Message-ID: References: <8433837.L6u1V86xfQ@pawels> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-11/txt/msg00222.txt.bz2 On Tue, 22 Nov 2011, Pawel Sikora wrote: > Hi, > > afaics the gcc-4.6 accepts following code: > > #include > 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