From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21594 invoked by alias); 29 Sep 2015 16:15:32 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 21481 invoked by uid 89); 29 Sep 2015 16:15:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 29 Sep 2015 16:15:26 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 77AA4C0F05E8; Tue, 29 Sep 2015 16:15:25 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-44.ams2.redhat.com [10.36.116.44]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8TGFNcV022053 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 29 Sep 2015 12:15:24 -0400 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id t8TGFM5O008510; Tue, 29 Sep 2015 18:15:22 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id t8TGFKh7008509; Tue, 29 Sep 2015 18:15:20 +0200 Date: Tue, 29 Sep 2015 16:26:00 -0000 From: Jakub Jelinek To: Jonathan Wakely Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [patch] Leave errno unchanged by successful std::stoi etc Message-ID: <20150929161520.GK1847@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <20150929151541.GZ12094@redhat.com> <20150929152515.GJ1847@tucnak.redhat.com> <20150929161020.GA12094@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150929161020.GA12094@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2015-09/txt/msg02226.txt.bz2 On Tue, Sep 29, 2015 at 05:10:20PM +0100, Jonathan Wakely wrote: > >That looks wrong to me, you only restore errno if you don't throw :(. > >If you throw, then errno might remain 0, which is IMHO undesirable. > > My thinking was that a failed conversion that throws an exception > should be allowed to modify errno, and that the second case sets it to > ERANGE sometimes anyway. Well, you can modify errno, you just shouldn't change it from non-zero to zero as far as the user is concerned. http://pubs.opengroup.org/onlinepubs/009695399/functions/errno.html "No function in this volume of IEEE Std 1003.1-2001 shall set errno to 0." Of course, this part of STL is not POSIX, still, as you said, it would be nice to guarantee the same. > > But I suppose it would be better to consistently set it to non-zero > when an exception is thrown, or consistently restore the original > value in all cases. > > >So, I'd say you want to restore it earlier, right after __convf, and > >immediately before that copy the current errno to some other temporary > >for the use in the condition? Or restore errno = __saved_errno; > >in all the 3 spots instead of just one. > > Or in a destructor so it happens however we exit the function, like > this ... Works for me. Jakub