From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18889 invoked by alias); 22 Nov 2011 17:23:05 -0000 Received: (qmail 18872 invoked by uid 22791); 22 Nov 2011 17:23:04 -0000 X-SWARE-Spam-Status: No, hits=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-yw0-f47.google.com (HELO mail-yw0-f47.google.com) (209.85.213.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Nov 2011 17:22:50 +0000 Received: by ywb20 with SMTP id 20so297070ywb.20 for ; Tue, 22 Nov 2011 09:22:50 -0800 (PST) Received: by 10.50.173.74 with SMTP id bi10mr25096842igc.4.1321982570069; Tue, 22 Nov 2011 09:22:50 -0800 (PST) Received: by 10.50.173.74 with SMTP id bi10mr25096827igc.4.1321982569962; Tue, 22 Nov 2011 09:22:49 -0800 (PST) Received: from coign.google.com ([2620:0:1000:2301:f2de:f1ff:fe40:72a8]) by mx.google.com with ESMTPS id dm1sm26115497igb.6.2011.11.22.09.22.48 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 22 Nov 2011 09:22:49 -0800 (PST) From: Ian Lance Taylor To: Pawel Sikora Cc: gcc-help@gcc.gnu.org Subject: Re: confusion about string.erase( --string.end() ) References: <8433837.L6u1V86xfQ@pawels> Date: Tue, 22 Nov 2011 18:18:00 -0000 In-Reply-To: <8433837.L6u1V86xfQ@pawels> (Pawel Sikora's message of "Tue, 22 Nov 2011 16:31:42 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes 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/msg00223.txt.bz2 Pawel Sikora writes: > 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++? 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